When we look at a close object, the background tends to be blurred out. But, if we look at a far object, everything far appears to be sharp.
Afterwards, when we view the photos, they don't appear the way they did when we looked through the viewfinder. The reason is because our eyes have "selective focus".
This area of sharpness is called the depth-of-field, and it extends in front of and behind the point that you actually focused on. The size of this focusing area is determined by three key factors - the aperture of the lens, the focal length of the lens used, and the distance you are from the subject. By varying these three factors, you have almost complete control over the depth-of-field in a picture.
When most of the picture is sharp, we say there's lots of depth-of-field. When only part is sharp, we say depth-of-field is limited. Whether you go for extensive or limited depth-of-field depends upon the subject matter and how you want it to appear.
1. The aperture.
There's a simple relationship between aperture and depth-of-field; the smaller the aperture (opening in the lens), the more extensive the depth-of-field. Period.
So if you want to keep as much as possible sharp, you should set as small an aperture as possible... f/16, f/22, etc. Depending on lighting conditions you may need to use a tripod or some other form of support at such small apertures, as the resulting long shutter speeds create a risk of camera-shake.
As I've mentioned before, if you want to concentrate attention on just one part of the scene, and throw the rest out-of-focus, you should select a large aperture. Exactly how large this can be depends on the maximum aperture of the lens you're using... F-1.8, F-2, F-3.5, etc. For general picture-taking, when you want most of the picture to be in focus, you might want to set an aperture of around f/8 or f/11. This is what some 'Program" modes set when you leave the camera to choose. When wanting to control the aperture, shoot in "Aperture Priority" or "Manual" modes.
2. The focal length of the lens.
Use a wide-angle lens and you'll get great depth-of-field, which makes it easy to keep everything in focus. Note: The wider the angle-of-view, the greater the depth-of-field. Choose a telephoto lens and the depth-of-field is very much less. Note: The longer the focal length, the more restricted the area of sharpness is.
3. The Camera-to-Subject Distance
Because of various technical reasons, the closer you get to the subject the more limited the depth becomes. This is true of ANY focal length. In fact, when shooting close-up subjects it can extend to just a few millimeters in front of and behind the subject.
Here are a few common reasons for choosing depth-of-field:
Everything sharp.
With subjects such as landscapes, groups and travel you'll usually want to keep everything sharp. Using a wide-angle lens set to a small aperture will give you the most depth-of-field, maybe even three feet to infinity. But there may be times when foreground interest is closer than that. Here you need to resort to a neat little technique called hyperfocal focusing that allows you to increase the depth-of-field to its max.
A good rule of thumb is; there's twice more depth-of-field behind the subject than in front of it. What this means is, if you photograph a distant subject such as a landscape and focus on infinity you waste lots of depth-of-field. By focusing a little closer, you'll have more area that appears in focus.
Main subject sharp with background completely out-of-focus.
There are some subjects where you want the main subject to stand out strongly from an out-of-focus background. Portraiture, where the emphasis is on the person, rather than the location, is probably being the most popular. The easiest way to do this is to use a telephoto lens at its widest aperture or moving your subject further from the background. Take care, though, that you focus accurately. The very limited depth-of-field will be unforgiving of any focusing errors. For portraits focus on the eyes for the best results.
Main subject sharp, with background out-of-focus but still recognizable.
Sometimes throwing the background completely out-of-focus is going too far. You may just want the background toned down a little so it doesn't compete for attention. You want to show the location but have the subject stand out a bit. A short telephoto lens, such as a 50-135mm lens, works good- especially with a mid-range aperture of around f/8.
Area of sharpness being minimal.
Sometimes, you may want to limit the depth-of-field to a very, very small area. Maybe just a person's eye in focus. Or maybe just a bee's head. You can accomplish this in quite a few ways but the most common ones are using a "Macro" lens or a telephoto lens set to the largest aperture at the closest focusing distance. To see your results before taking the picture, you can use the "step-down" button on your camera to view what the photo will have in focus.
Shoot, shoot, shoot!