(via Adorama w/ Gavin Hoey)
When you photograph landscapes, there are a number of things you have to get right in order to end up with a good looking photograph. Composition and exposure are obviously very important, but what about depth of field? Landscape photos sometimes have a foreground and a background and in order to make them "work" together in the frame, they both have to be sharp and in focus .
Basic photography suggests a solution that should work in theory. By setting the aperture to its smallest value, somewhere in the range of f/22, both foreground and background should have enough detail, right? That all depends on how far the foreground is from your camera. If there is some distance between the two, then yes, using a f/22 aperture and a long exposure could work. But if you want a really close foreground that almost requires a macro lens, and a spectacular background that has an equal amount of detail, you're going to have to use something else.
Focus stacking is the way to go. You might not have heard of it because it is not a very commonly used technique, but nevertheless it can be extremely useful in many types of photography. To understand focus stacking, think of it as bracketing, but instead of having multiple frames with different exposures, the variable here is focusing distance.
By taking it step by step, you will first find the scene you want to photograph with all the elements, set the camera on the tripod or in a fixed position and frame the picture to include foreground and background. By this time it will be obvious that letting the camera do the work automatically is out of the question. Put it in manual mode and set it to manual focus.
If you look on the top of your lens you will most likely see a distance scale that ranges from a few centimeters to infinity. Set it to macro or to the minimum focusing distance and take the first frame. After that, change focusing distance to a few meters, depending on how far the next elements in the frame are and take the second photo. Finally, set focus to infinity and take the third picture.
Finally, all you need to do is combine the three images into a single one that is sharp from one edge to another.
Photographer Gavin Hoey explains focus stacking with a practical demonstration and a quick Photoshop lesson.