← All posts

Lenses and Depth of Field: What You Buy With Light, and What It Costs

Lesson 2 of the Image Formation unit. A lens buys the brightness a pinhole cannot have and charges a plane of focus for it. Worked on a published scene: 93 mm at f/4 focused at 1.52 m is sharp from 1.500 m to 1.550 m, a band 5 cm deep. Stopping down to f/22 widens it to 0.277 m, a factor of 5.54 against an aperture ratio of 5.50, and the circle of confusion behind those numbers comes out at 0.0248 mm.

Luis Condados ·
The band that is acceptably sharp at f/4 and at f/22, on one distance axis, with the subject distance marked.
The band that is acceptably sharp at f/4 and at f/22, on one distance axis, with the subject distance marked.

A lens gathers a whole cone of light where a pinhole admits one ray, which is the only reason photographs can be taken in a fraction of a second. The price is that only one distance is truly in focus. On a published scene shot at 93 mm and f/4, focused at 1.52 m, the acceptably sharp band runs from 1.500 m to 1.550 m: five centimetres. Closing the aperture to f/22 widens it to 0.277 m, a factor of 5.54 against an aperture ratio of 5.50.

Where we are

Lesson 2 of image formation. Lesson 1 ended on the reason nobody builds a pinhole camera: a hole small enough to give one ray per pixel passes almost no light. Opening it admits more, and each sensor point starts receiving a cone rather than a ray, which is blur. A lens is the way out of that trade, and it comes with a bill.

A lens bends the cone back to a point

Intuition first: the pinhole rejects all the light that does not travel in one direction, and the lens redirects it instead. Rays leaving one scene point in many directions are bent so they meet again at one point behind the glass. Nothing is thrown away, so the sensor receives the whole cone the aperture admits, and the exposure that took minutes takes milliseconds [1].

That convergence only works for one object distance at a time. For an object at distance ss in front of a lens of focal length ff, the rays meet at image distance vv given by the thin-lens equation:

1f=1s+1v.\frac{1}{f} = \frac{1}{s} + \frac{1}{v}.

The sensor sits at one fixed vv, so exactly one ss is imaged as a point. Every other distance has its cone still converging, or already diverging again, when it reaches the sensor, and it lands as a disc instead. The diameter of that disc for a point at distance dd is

b(d)=f2Ndsd(sf),b(d) = \frac{f^2}{N}\cdot\frac{|d - s|}{d\,(s - f)},

where NN is the f-number, defined so that the aperture diameter is f/Nf/N. Both places NN appears say the same thing: a smaller opening makes a narrower cone, and a narrower cone spreads less by the time it lands.

lens, aperture f/Nsensoron the focus planenearer than the focus planeba point is “in focus” while b stays under the circle of confusion c
Only the green point converges at the sensor. The amber one is still converging when it gets there, so it paints a disc of diameter b. Depth of field is the range of distances for which b stays under a threshold c that the sensor and the viewer cannot tell apart from a point.

In focus is a tolerance, not a fact

Nothing except one plane is truly in focus, so “in focus” has to mean blurred by less than we can see. That threshold is the circle of confusion cc, and it is a claim about the sensor and the viewer rather than about the lens. Setting b(d)=cb(d) = c and solving gives the near and far limits, usually written through the hyperfocal distance HH:

H=f2Nc+f,dnear=s(Hf)H+s2f,dfar=s(Hf)Hs.H = \frac{f^2}{N c} + f, \qquad d_{\text{near}} = \frac{s(H-f)}{H + s - 2f}, \qquad d_{\text{far}} = \frac{s(H-f)}{H - s}.

That last agreement is the part worth keeping. Over a range where the subject distance is much larger than the focal length, depth of field grows in proportion to the f-number, so a photographer who knows they stopped down three stops knows the band got roughly eight times deeper without computing anything.

def dof_limits(f_mm, n, subject_m, coc_mm=0.02476):
    """Near and far limits of acceptable focus, in metres."""
    f = f_mm / 1000
    a = f * f / (n * coc_mm / 1000)          # hyperfocal minus f
    u = subject_m - f
    far = float("inf") if u >= a else subject_m * a / (a - u)
    return subject_m * a / (a + u), far
// Near and far limits of acceptable focus, in metres.
std::pair<double, double> dof_limits(double f_mm, double n, double subject_m,
                                     double coc_mm = 0.02476) {
  const double f = f_mm / 1000.0;
  const double a = f * f / (n * coc_mm / 1000.0);   // hyperfocal minus f
  const double u = subject_m - f;
  const double far = (u >= a) ? std::numeric_limits<double>::infinity()
                              : subject_m * a / (a - u);
  return {subject_m * a / (a + u), far};
}

Now you try

Start on the scene above and stop down one aperture at a time; the green band on the depth axis grows in step with the f-number. Then drag the subject closer and watch it collapse, and switch the sensor format to see every number move without the lens changing at all.

Try it: what is in focus

In the wild

Every photograph carries the numbers this lesson needs, in its own EXIF. Here is one that does, and the prediction can be checked against the picture.

A market stall shot on a Nikon D750 at 300 mm, f/4, with the camera recording a subject distance of 14.96 m. Feeding that to the depth-of-field relation, with the usual 0.030 mm circle of confusion for full frame:

H=f2Nc+f=30024×0.03+300=750mH = \frac{f^2}{N c} + f = \frac{300^2}{4 \times 0.03} + 300 = 750\,\text{m} near=14.67 m,far=15.26 m0.59 m of depth\text{near} = 14.67\ \text{m}, \qquad \text{far} = 15.26\ \text{m} \qquad \Rightarrow \qquad \textbf{0.59 m of depth}

What it means: at fifteen metres, a 300 mm lens at f/4 holds 59 centimetres in focus. Not the stall — a slice through it. And the picture agrees: measuring local sharpness in ten horizontal bands gives 19, 16, 16, 47, 124, 356, 425, 256, 168, 122. The sharpest band is 26 times sharper than the softest, and everything outside that one slice is visibly gone.

Three strips from the same photograph: a blurred awning far behind, sharp fruit in the middle, and a nearer row also softening
Three depths in one frame. The awning behind is metres outside the 0.59 m slice and is unrecognisable; the fruit inside it is sharp. Source: “Marrakech souk fruit vendor” by Mustang Joe (Wikimedia Commons), CC0.

The hyperfocal distance is the other half of the story: at 750 m, focusing this lens at infinity would still leave everything closer than 375 m soft. A 300 mm lens simply does not do “everything in focus”, and no aperture on this body changes that by much.

Where this breaks

Depth of field is not a property of the lens. The same 93 mm at f/4 gives a five-centimetre band on this camera and a different one on any other, because cc changes. Switch the lab to the phone format at 0.005 mm and the band shrinks by a factor of five without touching a single optical parameter. Any depth-of-field number quoted without its sensor and its viewing assumptions is incomplete.

The threshold hides a choice nobody states. The 0.030 mm that full-frame tables use comes from assuming a print of a particular size viewed from a particular distance by an eye of particular acuity. Look at the same file at 100% on a monitor and the tolerance you actually have is smaller, so the true band is narrower than the table says.

And one row of the source figure does not reconcile. The same DPDD caption gives a f/22 depth of field of 0.70–5.80 m, which the formula cannot produce from that figure’s own 93 mm at 1.52 m. Reproducing 0.70–5.80 m needs a 29.1 mm lens at 1.249 m. Whether that row describes a different scene, a range across the dataset, or an error is not something the figure settles, so this lesson reports both the prediction and the discrepancy rather than choosing.

The blur here is geometry only. Every formula above treats light as rays. Stop down far enough and diffraction takes over, spreading a point regardless of how well the cone converges, so past roughly f/16 on this sensor the extra depth comes with a softer image everywhere.

Next

The thin-lens model still assumes every ray bends by exactly the right amount. Real glass does not oblige, and it misses by more the further from the axis a ray arrives, which is the residual lesson 1 measured and could not explain. Distortion, vignetting and aberration is where that goes.

Run it: every code block on this page has a cell in the unit’s notebook — open it in Colab.

References

[1] Forsyth, D. A., & Ponce, J. (2012). Computer Vision: A Modern Approach (2nd ed.), ch. 1 “Geometric Camera Models”, §1.1.3 “Cameras with Lenses” (p. 8). Pearson.

[2] Abuolaim, A., & Brown, M. S. (2020). Defocus Deblurring Using Dual-Pixel Data. European Conference on Computer Vision (ECCV) 2020. arXiv:2005.00305