# Is there a formula to calculate DOF?

Photography Asked by vivek_jonam on October 5, 2020

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?

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 ;)

Correct answer by Matt Grum on October 5, 2020

I don't have the rep to comment...so @KT100 http://graphics.stanford.edu/courses/cs178-09/ explains that the formula is an approximation...it needs very specific numbers to get even close to DoF

Answered by jt peabody on October 5, 2020

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

Answered by Alan Marcus on October 5, 2020

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

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


Answered by KT100 on October 5, 2020

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 :)

Answered by psarossy on October 5, 2020

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.

Answered by damned truths on October 5, 2020

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.

Answered by Miguel on October 5, 2020

## Related Questions

### How can I use the 200 seconds exposure time in Raspberry Pi HQ camera?

0  Asked on June 20, 2021 by xme

### Is it possible to do infrared photography with digital cameras?

3  Asked on June 19, 2021

### Hardware for scanning diapostives or negatives using flatbed scanner?

4  Asked on June 19, 2021

### Why color-wheel websites (Adobe…) claim these colors are complementary

1  Asked on June 18, 2021

### Can alignment of the bed rails of a Speed Graphic be repaired?

2  Asked on June 18, 2021 by toasthouse

### Holga 120 WPC exposure times

2  Asked on June 18, 2021

### Will a DSL Camera Field Monitor on a D7500 Display What Is Shown In The Liveview

2  Asked on June 18, 2021 by robertcode

### Why does GIMP increase the size of exported JPEG files?

2  Asked on June 18, 2021 by sarahluw

### What are these black lines in the photograph?

3  Asked on June 18, 2021 by devashish-das

### Correct exposure negative scan

1  Asked on June 17, 2021 by ljuslykta

### Saving a isolate prop image with shadow to png

1  Asked on June 17, 2021 by kphotog

### How do I create an infinite picture-in-picture effect?

3  Asked on June 17, 2021

### How to start a Sony A7iii directly in playback mode?

2  Asked on June 17, 2021

### What is the difference between pixel pitch and pixel density?

2  Asked on June 16, 2021

### How to combine an autofocus teleconverter with a manual-focus lens

1  Asked on June 16, 2021 by tharter

### Batch scanning of family archive: speed of flatbed vs. film scanners?

1  Asked on June 16, 2021

### Aperture iris in front of lenses (in object space)

6  Asked on June 16, 2021 by euri-pinhollow

### How do I know if I’m ready to turn professional?

6  Asked on June 16, 2021 by aj-finch

### Canon T6i Auto focus works on Live view but stops auto focusing on view finder

0  Asked on June 16, 2021 by sjj

### Effect of assigning an ICC color profile at different stages

3  Asked on June 15, 2021