The limit of depth of field
Stopping down to f/16 or f/22 increases depth of field, but diffraction begins to soften the whole image. In close-up and macro work, depth of field can be millimeters even at small apertures.

The solution
Take several frames, moving the plane of focus a little each time, then blend the sharp parts into a single image.
How to shoot a stack
- Camera on a sturdy tripod; manual focus; fixed exposure.
- Choose an aperture near the lens’s sweet spot, typically f/5.6 to f/8.
- Focus on the nearest point, take a frame, then shift focus slightly farther and repeat until you pass the farthest point.
- Overlap each frame’s sharp zone with the next. Ten to forty frames are common for macro.
Blending
Photoshop’s Auto-Blend Layers (stack images) or dedicated software such as Helicon Focus does the merge. Check the result at 100% for ghosting or halos and fix by masking.

Where it helps
Macro, product and still life, and landscape with a very close foreground and distant mountains. Subjects that move, such as flowers in wind, make it hard.