What is Focus Stacking?
Focus stacking (also known as focal plane merging and z-stacking or focus blending) is a digital image processing technique which combines multiple images taken at different focus distances to give a resulting image with a greater depth of field (DOF) than any of the individual source images.
– from Wikipedia
How should I take the photos?
In terms of composition, both the camera and all of your subjects need to remain in the exact same position for all of your images. Take a minimum of two photos with the focus on each one at a slightly different distance. Even if your lens focuses in a way that introduces slight distortion of the out-of-focus areas, Photoshop can align automatically for you, so just concentrate on the photos without worrying about post-processing.
The Automated Method
After transferring all of your images to your computer you need to load all of them into a single Photoshop document. For up to 3 images, opening the first one and then using File > Place for the others is okay. If you have a larger number of photos, however, try File > Scripts > Load Files Into Stack.
A window entitled Load Layers will appear, allowing you to import your images. Press the browse button and navigate to wherever your images are, then select them all and pick Open.
After selecting the images, you can optionally tick Attempt to Automatically Align Source Images if you think the photos might not be perfectly aligned.
Press OK and watch as Photoshop does the work for you, turning each and very image into a layer.
With the top layer selected, hold Shift and click the last layer to have them all selected.
Now go to Edit > Auto Blend Layers.
From the newly appeared window choose Stack Images, and leave Seamless Tones and Colors checked.
Click OK to begin the process (usually from 2 to 5 minutes depending on image size and computer performance).
Represented with a GIF, this is how Photoshop gradually stacks up images:
Then it gives you the final result:
If you’re happy with the final result, you can press a quick Ctrl + Shift + S to save your final image as a new file.
Check out Page 2 for the Manual Method.