In this paper, a numerical model using three-dimensional finite difference code FLAC3D is proposed for analysing the stability of an oil well drilled in four formations. Normalized Yielded Zone Area (NYZA, i.e., the ratio of surrounding yielded cross-sectional area to initial area of well) has been determined for different mud pressures. In each formation, by interpolating of obtained NYZA equal to one, the optimized mud pressure was determined using MATLAB software. Practical data including geomechanical parameters along with drilling data from one of Iranian oilfields, Mansouri-54 well have been utilized in this analysis. in situ stress was determined using stress polygon method and conducting hydraulic fracturing data in the field. Analytical solution using the Mogi–Coulomb and the Hoek–Brown failure criteria has been carried out and results are compared with the presented model. The results demonstrated that the NYZA and Hoek–Brown criteria might underestimate and overestimate the drilling mud pressure, respectively, and should be used cautiously. In the inclined section of the well, plastic zone showed more extension in the lower part than upper part of the well because of the high stress concentration.