Inverse modeling is one of the most elegant geophysical tools for obtaining 2-D and 3-D images of geological structure. Determination of the geometry of bedrock, by nonlinear inverse modeling of gravity data, is the aim of this paper. The algorithm uses a nonlinear iterative procedure for simulation of bedrock geometry. At the first step, the nonlinear problem changes to a linear problem by a proper approximation and standard method. The second step is the parameterization of the model. Finally, an initial model is suggested on the basis of geological and geophysical assumption and using the numerical analysis, the Jacobean matrix is calculated. The inversion will improve the initial model in each iteration, considering the differences between observed and calculated gravity anomalies, based on Levenberg-Marquardt's method. The usual practice of inverting gravity anomalies of two-dimensional bodies is to replace their cross sections by an n-sided polygon and to determine the locations of the vertices that best explain the observed anomalies. The initial coordinates of the vertices are assigned and later modified iteratively so as to minimize the differences between the observed and calculated anomalies. The estimation of the initial values is a separate and indeed a critical exercise. This selection determines the convergent solution to the problem. It seems that inversion schemes replacing the two-dimensional bodies by a series of juxtaposing prisms, instead of a polygonal cross section, do not require any a priori calculation of the initial values of the parameters that define the outline of the body. This paper presents such an inversion scheme for determining the density surface such as the basement topography above an assigned depth Z and density contrast . The method does not require input of initial values of any other parameters. It is also applicable for determining structure with a flat top or a flat bottom. The program determines depths to the top of the basement surface below each point of gravity anomaly along a profile. The practical effectiveness of this method is demonstrated by the inversion of synthetic and real examples. The real data is acquired over the site of the construction of a new line of the Tehran underground railway. Finally the results are compared with the geological information.