When you focus on a subject at a specific distance from the camera, that object will be in-focus. As you know, objects that are close by, both in front and behind this principle subject will likely be in-focus also. We are talking about a span of distance fore and aft of the focus point that will image acceptably sharp. This span is called depth-of-field.
We can both expand and contract the depth of field span by changing the lens aperture setting. Tiny aperture numbers like f/22 or f/16 or f/11 expand the depth of field zone. f/22 has the greatest span of depth of field followed by f/16, etc. So the simple answer is to use f/22 or f/16 when taking the picture.
The first step you must take is to read your camera manual. If you do, you will learn about depth-of-field and what settings your camera offers that will maximize depth of field. I will bet your camera has a landscape or scenery mode that will automatically make the needed adjustments for you.
Did you know that you can set your aperture and the distance you are focused upon in a special way that maximizes depth of field? That setting is called the “hyperfocal distance” setting. Such a setting keeps far distant objects - objects at infinity (∞) - in focus and maximizes how close objects will image in-focus.
Hyperfocal settings for 50mm lens with regards to aperture is as below -
- f/8 : 34 feet depth of field span is 17 feet to ∞
- f/11 : 25 feet depth of field span is 12 ½ feet to ∞
- f/16 : 17 feet depth of field span is 8 ½ feet to ∞
- f/22 : 12 feet depth of field span is 6 feet to ∞
Note: infinity symbol (∞) means as far as the eye can see (from old French).