Aperture, depth of field and focal length
Depth of field is also affected by focal length. If you shoot with a wide-angle lens, you’ll capture a larger depth of field, which keeps the scene sharp from front to back. At f/5.6 on a wide-angle 24mm lens, for example, you’ll get a broader depth of field than at f/5.6 on a 100mm telephoto lens. This is why wide-angle lenses are ideal for landscapes, while the shallower depth of field of a telephoto lens enables you to isolate a subject you’ve zoomed in on, making them well suited for shooting wildlife.
Using depth of field to determine which parts of an image are in sharp focus is a creative choice, of course.