One of the most important factors that limit the performance of diffractive optical elements (DOE’s) is the depth accuracy of the relief structure. A common procedure for fabricating DOE’s is the binary optics procedure, in which binary masks are used for the fabrication of a multilevel relief structure. Here an analytic procedure for calculating the optimal depth levels of DOE’s, the phase bias, and the decision levels is presented. This approach is based on the minimization of the mean-squared error caused by the quantization of the continuous profile. As a result of the minimization an optimal value for the etching depth of each photolithographic mask is determined. The obtained depth values are, in general, different from the depth values used by the conventional multilevel approach. Comprehensive mathematical analysis is given, followed by several computer simulations that demonstrate the advantages of the proposed procedure.