The estimation of basement depth is one of the major geophysical objectives which endure many uses in mineral exploration and is particularly important in detecting favorable targets for hydrocarbon exploration. The main objective in applying most geophysical methods is to interpret and characterize geological structures using measured data, a task that is very difficult to fulfill through physical modeling. The construction of physical models for actual density and magnetic susceptibility property distributions incorporating geometric properties such as structural depth is a costly and time consuming task compared to the estimation of model parameters from geophysical measurement data used in current research. Moreover, there are many important sedimentary structures that may present in petroleum reservoir so that gravity and magnetic data could be used to resolve structural settings such as bedrock topography. Inverse modeling is usually considered as a numerical tool for obtaining two dimensional and 3D images of subsurface structures. In this research, nonlinear inverse modeling of gravity and magnetic data is used to determine the bedrock topography. The modeling process is in such a way that the bedrock is modeled by a series of right-angled blocks, upon which the blocks depth could be estimated. Algorithms based on the Parker-Ouldenberg method and regression regression method actually improve the initial model in a number of iterations until a desirable convergency vriteria is acheived. Two useful models for estimating three-dimensional basement are juxtaposing rectangular prisms and the polygonal bodies in which juxtaposing rectangular prisms inversion not only faster, but also does not bear the difficulties associated with the polygonal inverse modeling. In this study, the three-dimensional basement is modeled by equating it to a series of juxtaposing rectangular prisms and calculating their thicknesses using Taylor series to linearize our problem. In order to demonstrate the accuracy of the provided computer programs, the modeling was performed using the Euler deconvolution method and the SPI deconcentration in the Geosoft Oasis Montaj software environment and then compared with modeling computer programs in the MATLAB software environment. In the end of the modeling, some parts of the Gachsaran and Ahwaz oil field basins were compared and the results were consistent with available geological information and settings.