# Is there a formula to calculate DOF?

I am pretty clear about that DOF depends on:

1. Focal length
2. Aperture or f-stop
3. Distance from subject
4. Sensor size

and more (as pointed out in this comment).

But my question is: Is there any formula that relates all these factors with Depth of Field?

Given these values is it possible to accurately calculate the Depth of Field?

• There are two more things to consider: (5) the size of the final image; and (6) whether you are concerned with the "zone of acceptable sharpness" when the other five factors are taken into account, or with the "zone of sufficient blurriness".
– user2719
Commented Jul 1, 2012 at 11:15

Depth of field depends on two factors, magnification and f-number.

Focal length, subject distance, size and circle of confusion (the radius at which blur becomes visible) jointly determine the magnification.

Depth of field does not depend on lens or camera design other than the variables in the formula so there are indeed general formulas to calculate depth of field for all cameras and lenses. I don't have them all committed to memory so I'd only be copying and pasting from Wikipedia: Depth of field.

A better answer to your question would be to go through the derivation of the formulas from first principles, something I've been meaning to do for a while but haven't had time. If anyone wants to volunteer I'll give them an upvote ;)

• That's somewhat mixed up. Magnification is just determined by the ratio of focal length to subject distance. Magnification and f-number determine at which rate depth relative to an object's width grows into blur relative to the object's width. To determine actual depth of field, you need to define just what size of blur you still consider in-focus: that's essentially the circle of confusion. Commented Sep 26, 2020 at 12:54

You wanted the math, so here it goes:

You need to know the CoC of your camera, Canon APS-C sized sensors this number is 0.018, for Nikon APS-C 0.019, for full frame sensors and 35mm film the number is 0.029.

The formula is for completeness:

CoC (mm) = viewing distance (cm) / desired final-image resolution (lp/mm) for a 25 cm viewing distance / enlargement / 25


Anothe way of doing this is the Zeiss formula:

c = d/1730


Where d is the diagonal size of the sensor, and c is the maximum acceptable CoC. This yields slightly different numbers.

You need to calculate the hyperfocal distance first for your lens and camera (this formula is inaccurate with distances close to the focal length e.g. extreme macro):

HyperFocal[mm] = (FocalLength * FocalLength) / (Aperture * CoC)


e.g.:

50mm lens @ f/1.4 on a full frame:      61576mm (201.7 feet)
50mm lens @ f/2.8 on a full frame:      30788mm (101 feet)
50mm lens @ f/1.4 on a Canon APS frame: 99206mm (325.4 feet)
50mm lens @ f/2.8 on a Canon APS frame: 49600mm (162.7 feet)


Next you need to calculate the near point which is the closest distance that will be in focus given the distance between the camera and the subject:

NearPoint[mm] = (HyperFocal * distance) / (HyperFocal + (distance – focal))


e.g.:

50mm lens @ f/1.4 on a full frame with a subject at 1m distance: 0.984m (~16mm in front of target)
50mm lens @ f/1.4 on a full frame with a subject at 3m distance: 2.862m (~137mm in front of target)
50mm lens @ f/2.8 on a full frame with a subject at 1m distance: 0.970m (~30mm in front of target)
50mm lens @ f/2.8 on a full frame with a subject at 3m distance: 2.737m (~263mm in front of target)

50mm lens @ f/1.4 on a Canon APS frame with a subject at 1m distance: 0.990m (~10mm in front of target)
50mm lens @ f/1.4 on a Canon APS frame with a subject at 3m distance: 2.913m (~86mm in front of target)
50mm lens @ f/2.8 on a Canon APS frame with a subject at 1m distance: 0.981m (~19mm in front of target)
50mm lens @ f/2.8 on a Canon APS frame with a subject at 3m distance: 2.831m (~168mm in front of target)


Next you need to calculate the far point which is the furthest distance that will be in focus given the distance between the camera and the subject:

FarPoint[mm] = (HyperFocal * distance) / (HyperFocal – (distance – focal))


e.g.:

50mm lens @ f/1.4 on a full frame with a subject at 1m distance: 1.015m (~15mm behind of target)
50mm lens @ f/1.4 on a full frame with a subject at 3m distance: 3.150m (~150mm behind of target)
50mm lens @ f/2.8 on a full frame with a subject at 1m distance: 1.031m (~31mm behind of target)
50mm lens @ f/2.8 on a full frame with a subject at 3m distance: 3.317m (~317mm behind of target)

50mm lens @ f/1.4 on a Canon APS frame with a subject at 1m distance: 1.009m (~9mm behind of target)
50mm lens @ f/1.4 on a Canon APS frame with a subject at 3m distance: 3.091m (~91mm behind of target)
50mm lens @ f/2.8 on a Canon APS frame with a subject at 1m distance: 1.019m (~19mm behind of target)
50mm lens @ f/2.8 on a Canon APS frame with a subject at 3m distance: 3.189m (~189mm behind of target)


Now you can calculate the total focal distance:

TotalDoF = FarPoint - NearPoint


e.g.:

50mm lens @ f/1.4 on a full frame with a subject at 1m distance:  31mm
50mm lens @ f/1.4 on a full frame with a subject at 3m distance: 228mm
50mm lens @ f/2.8 on a full frame with a subject at 1m distance:  61mm
50mm lens @ f/2.8 on a full frame with a subject at 3m distance: 580mm

50mm lens @ f/1.4 on a Canon APS frame with a subject at 1m distance:  19mm
50mm lens @ f/1.4 on a Canon APS frame with a subject at 3m distance: 178mm
50mm lens @ f/2.8 on a Canon APS frame with a subject at 1m distance:  38mm
50mm lens @ f/2.8 on a Canon APS frame with a subject at 3m distance: 358mm


So the complete formula w/ CoC and HyperFocal precalculated:

TotalDoF[mm] = ((HyperFocal * distance) / (HyperFocal – (distance – focal))) -(HyperFocal * distance) / (HyperFocal + (distance – focal))


Or simplified:

TotalDoF[mm] = (2 * HyperFocal * distance * (distance - focal)) / (( HyperFocal + distance - focal) * (HyperFocal + focal - distance))


With CoC precalulated: I've made an attempt to simplify the following equations with the following substitutions: a = viewing distance (cm) b = desired final-image resolution (lp/mm) for a 25 cm viewing distance c = enlargement d = FocalLength e = Aperture f = distance X = CoC

TotalDoF = ((((d * d) / (e * X)) * f) / (((d * d) / (e * X)) – (f – d))) - ((((d * d) / (e * X)) * f) / (((d * d) / (e * X)) + (f – d)))


Simplified:

TotalDoF = (2*X*d^2*f*e(d-f))/((d^2 - X*d*e + X*f*e)*(d^2 + X*d*e - X*f*e))


Even further simplified with WolframAlpha:

TotalDoF = (2 * d^2 * e * (d - f) * f * X)/(d^4 - e^2 * (d - f)^2 * X^2)


Or if nothing is precalculated, you get get this monster, which is unusable:

TotalDoF = ((FocalLength * FocalLength) / (Aperture * (viewing distance (cm) / desired final-image resolution (lp/mm) for a 25 cm viewing distance / enlargement / 25)) * distance) / ((FocalLength * FocalLength) / (Aperture * (viewing distance (cm) / desired final-image resolution (lp/mm) for a 25 cm viewing distance / enlargement / 25)) – (distance – focal)) - ((FocalLength * FocalLength) / (Aperture * (viewing distance (cm) / desired final-image resolution (lp/mm) for a 25 cm viewing distance / enlargement / 25)) * distance) / ((FocalLength * FocalLength) / (Aperture * (viewing distance (cm) / desired final-image resolution (lp/mm) for a 25 cm viewing distance / enlargement / 25)) + (distance – focal))


Simplified:

(50*a*b*c*d^2*f*e*(d-f))/((25*b*c*d^2 - a*d*e + a*f*e)*(25*b*c*d^2 + a*d*e - a*f*e)


So basically use recalculated CoC and HyperFocal :)

If you want to see a practical implementation of the depth of field formulas you can check out this Online Depth of Field Calculator. The source of the linked HTML page has all the formulas implemented in Javascript.

Yes, there are formulas. One can be found at http://www.dofmaster.com/equations.html. These formulas are used on this calculator, it also explains depth of field in more detail. I have used this site several times and have found it to be reasonably accurate after doing practical tests myself.

Here's a simple DOF formula. Hope it helps.

    DOF = 2 * (Lens_F_number) * (circle_of_confusion) * (subject_distance)^2 / (focal_length)^2


P = point focused upon

Pd = distant point sharply defined

Pn = near point sharply defined

D = diameter of circle of confusion

f = f-number

F = focal length

Pn = P ÷ (1+PDf÷F^2)

Pd = P ÷ (1-PDf÷F^2)

Industry standard to set D = 1/1000 of the focal length. For more precise work use 1/1500 of the focal length. Presume 100mm focal length then 1/1000 of 100mm = 0.1mm or 1/1500 = 0.6666mm