Focus stacking
Focus stacking means shooting several photos of one scene, each focused at a different distance, and blending them into a single image sharp throughout.
Also known as: focus bracketing, depth stacking, image stacking
Focus stacking consists of taking several photos of the same scene, each focused at a different distance, and merging them in editing to produce a single image that is sharp from front to back, something impossible to achieve with the depth of field of a single shot.
The step between shots must be smaller than the sharp zone of each one: if they don't overlap, blurry strips are left between them.
It is the answer to a physical problem: in macro photography the depth of field is measured in millimeters, and in landscape with a very close foreground not even the hyperfocal distance covers everything from the rock at your feet to the mountain.
How many shots do I need?
Divide the depth of the subject by the sharp zone of a single shot, and add 20 to 30% margin so the strips overlap. The sharp zone at short distances depends on magnification far more than on distance: at 1:1 and f/8 on full frame it is around 1 mm, and no reasonable aperture multiplies it.
Subject: Insect 20 mm deep; Magnification: 1:1; Aperture: f/8; Sharp zone per shot: ~1 mm; Shots: 25 – 30
Subject: Flower 40 mm deep; Magnification: 1:2; Aperture: f/8; Sharp zone per shot: ~2.9 mm; Shots: 18 – 20
Subject: 15 cm product; Magnification: 1:5; Aperture: f/11; Sharp zone per shot: ~2 cm; Shots: 10 – 12
Subject: Tabletop still life; Magnification: 1:10; Aperture: f/11; Sharp zone per shot: ~7 cm; Shots: 4 – 6
Subject: Landscape with a rock at 0.5 m; Magnification: —; Aperture: f/11; Sharp zone per shot: —; Shots: 2 – 4
In landscape the split is simpler than it looks: one shot focused on the close foreground, another at mid-distance and another at the hyperfocal distance are usually enough. The depth of field calculator tells you where those three points fall with your focal length.
What settings do I use during the series?
Everything manual and nothing touched between shots: aperture, shutter speed, ISO and white balance locked. If the exposure varies by half a stop between shots, the stack leaves brightness bands where the source of sharpness changes.
In macro with flash, f/8, 1/200 s, ISO 100 is a starting point on full frame, with the flash regulating the power. Keep in mind that at 1:1 the effective aperture is double the marked one: an f/8 behaves like f/16 in terms of diffraction and costs 2 stops of light, which is exactly why flash stops being optional.
To move the focus you have two paths. Turning the focus ring is fast and works, although it slightly changes the magnification between shots and the software compensates by scaling. A macro rail moves the whole camera and keeps the magnification constant, at the cost of weight and time. Many current cameras include an automatic focus shift mode that shoots the entire series with the step you specify.
Common mistakes
Taking steps that are too large. If the step exceeds the sharp zone, blurry strips are left between the focused planes, and there is no way to fix it without repeating the series. When in doubt, better too many shots than too few.
Stopping down to need fewer shots. At f/22 and 1:1 the effective aperture is f/44 and diffraction turns the whole image soft. Stacking ten shots at f/8 gives more real detail than a single one at f/22.
Ignoring the wind. A leaf that moves 2 mm between shot 4 and shot 12 produces ghosts that are impossible to retouch. Outdoors, shoot in the early hours or set up an umbrella as a windbreak.
For the step-by-step process in landscape, see focus stacking in landscape, step by step, the guide to depth of field and the one on macro photography.