How does auto focus work on modern cameras? How accurate is it?
An AF system essentially consists of a sensor system that is linked (via the camera's processor) to the AF motor, which will either be in the lens or the camera body depending on the model.
There are 2 kinds of autofocus. Active AF uses methods such as ultrasonics or infrared to measure the distance between the camera and the subject. A pulse is emitted from the camera, bounces off the subject, and returns. The time this takes is calculated in-camera and used to determine the distance. This kind of AF is independent of the lens/mirror system of the camera.
Passive AF analyses the image in the viewfinder instead. 2 methods are used in Passive AF. The first is Phase Detection. Here the image is split into two in the camera and the different phases of the two images are analysed. It achieves range-finding by essentially comparing how the two images diverge on the sensor. This is the system most modern DSLRs use, as it is the most accurate.
The second passive AF system is Contrast Detection. This is most commonly used in video cameras, and in DSLRs when in live view mode (essentially the same as a video camera). It works by analysing the contrast between pixels; the better the image is in focus, the greater the difference in intensity between pixels. So the camera checks intensity, focuses a little, checks again, etc., until it achieves a focus that gives an acceptable (preprogrammed) intensity difference. There is no actual range-finding going on. Contrast Detection is generally slower and less accurate than Phase Detection.
As for accuracy, generally, if used correctly, AF systems are very accurate (Passive Phase Detection being the most accurate). However, they often have problems in low-light (hence the AF lamp that comes on when you try and focus in the dark). The user also has to make sure that they are focusing on the correct point (e.g. focusing on the subject not the background).
Here's the best summary I've found on the subject.
It is written by Roger Cicala, the CEO of lensrentals.com. His blog is one of my favorites.
Here is a good write-up on all things auto-focus. For a very complete review have a read.