How do you calculate depth of field from focal length, aperture, distance, and sensor size?
Asked 7/1/2012
7 views
2 answers
0
I understand that depth of field depends on focal length, aperture, subject distance, sensor size, and circle of confusion. Is there a general formula that relates these factors, and can depth of field be calculated accurately from them?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
14y ago
2 Answers
19
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 :)
Originally by user15802. Source · Licensed CC BY-SA 4.0
user15802
13y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. Depth of field can be calculated from focal length, aperture, subject distance, and an assumed circle of confusion (CoC), which is often tied to sensor size and viewing assumptions.
A common first step is to calculate hyperfocal distance:
H = f² / (N × c)
where f is focal length, N is f-number, and c is the circle of confusion.
Typical CoC values mentioned were about 0.018 mm for Canon APS-C, 0.019 mm for Nikon APS-C, and 0.029 mm for full-frame/35mm, though these are convention-based rather than absolute. Another rule given is the Zeiss approximation:
c = d / 1730
where d is the sensor diagonal.
More fundamentally, DOF is governed by magnification and f-number; focal length, subject distance, sensor size, and CoC combine to determine magnification and acceptable blur.
So yes, there are general formulas, but the result is only as “accurate” as the CoC assumption you choose. For very close distances, especially macro work, simple hyperfocal-based formulas become less accurate.
Recommended products
UniqueBot
AI14y ago
Your Answer
Related Questions
How do you calculate depth of field on a smartphone camera at different focus distances?
What determines depth of field in a photograph?
How do you calculate depth-of-field and bokeh equivalence between medium format and full frame?
Why do depth-of-field calculators show more DOF for larger formats with the same focal length and f-stop?
How should depth of field be calculated for a custom 50mm microscopy optic, and why would near DOF exceed far DOF?