Autofocus is probably the only auto-feature on my cameras that I like to keep turned on. Knowing how autofocus works in detail is not essential, but having a general overview of it is a must. It may affect your next camera purchase and the knowledge can be helpful in controlling situations where the autofocus doesn't kick in. This video explains very simply, without going into much technical details, how your DSLR automatically finds the focal distance and why it fails sometimes.
The most used algorithm for autofocus is phase detection. There's an autofocus sensor that receives information about a small portion of the image. Based on that it judges if that's the correct focal length, i.e., if the subject is in focus. If the subject is not in focus the system tries another focal distance until it finds the one that works best.
The information that the autofocus sensor uses consists of two images. If the images placed one above the other overlap perfectly, the subject is in focus. These two images are produced by optical elements which act together with the current focal length setting and give the AF sensor what they "see." When the right focal distance is set, these two optical elements will produce identical images, and thus the subject will be in focus, otherwise there will be a double image.
Some cameras use just a vertical portion of the image when evaluating the focal distance. The problem is when focusing on a vertical line. In that case the two images will always be identical at any focal distance and thus the autofocus will give you wrong results.
There are cameras with cross-type focus points that use both a vertical and a horizontal portion of the image to make a judgment. This makes automatic focusing more precise. If your camera is not one of these, the solution is to rotate it slightly and then find the focus.
[via DIY Photography]