You press the shutter, the photo comes out blurry and you blame your pulse. It is almost never your pulse: the autofocus system simply had nothing to grab hold of. Focusing is not a single act that happens at the moment of the shot; it is a loop that has been running since you opened the camera app, dozens of times per second, and that runs out of signal at the decisive moment.
A lens that moves and a criterion to know whether it got it right
In any lens, focusing means shifting a group of elements —the focus group— along the optical axis until the image it projects lands exactly on the sensor plane. In a DSLR that job fell to a mechanical cam driven by a motor in the body; in a phone it is done by an electromagnetic actuator the size of a lentil. It is a voice coil motor, or VCM: a coil suspended in a permanent magnetic field that pushes the lens barrel with a force proportional to the current running through it. Typical travel: between 200 and 400 micrometres, in steps of less than one micron.
The hard part is not moving the lens, it is knowing when it sits in the right place. A sensor does not “see” defocus the way an eye does; it only delivers a matrix of numbers. All modern autofocus consists of manufacturing, out of those numbers, a signal that says in which direction and by how much to correct. And that is where the two big families split.
Contrast: climbing the hill blindfolded
The classic method, contrast detection (CDAF), measures the high-frequency energy of the image. A derivative filter is applied over the frame —Sobel, Laplacian or a plain sum of differences between neighbouring pixels— and yields a number: the more energy, the sharper the edges, the better the focus plane. The algorithm nudges the lens one step, measures again and compares with the previous reading. If the number goes up, it keeps going the same way; if it drops, it turns around. It is a hill-climbing search, and its flaw is structural: it only knows the height of the terrain, not the map. It cannot tell whether the peak lies ahead or behind, so it has to feel its way, and in low-contrast scenes —a blank wall, a dark room, a night sky— the hill flattens out and the system bounces from end to end. That is the hunting you hear as a hum in videos.
Phase detection: two views of the same world
Phase detection (PDAF) solves the problem by measuring geometry instead of sharpness. The idea comes from the rangefinders of 1930s cameras: if you split the lens’s exit pupil into two halves, left and right, each half projects a slightly displaced image of the same object. When the object sits on the focus plane, the two images coincide; when it is in front or behind, they drift apart. The size of that separation measures how far off focus is, and its sign tells you which side the focused plane lies on. A single reading is enough: no feeling around.
On a CMOS sensor this is implemented by masking half of the photodiode of certain pixels under an opaque metal layer. Even pixels look only at the left half of the lens, odd pixels at the right half, and the readout circuit compares the two sub-images row by row, like a correlator. The cost is that those pixels lose roughly half the light they receive. The mass-market fix in phones is Dual Pixel: instead of masking isolated pixels, each photodiode is split into two halves read separately. You lose resolution in the phase reading but not light, you get coverage across the whole frame —essential for tracking subjects anywhere in the scene— and, as a bonus, the difference between the two halves yields a per-pixel depth map, which is what feeds portrait mode.
Square variants (quad pixel) split the pixel into four and detect phase on both vertical and horizontal edges, which is critical when the subject is a flat surface in one direction: a fluorescent tube, a window blind, a horizon.
When there is neither contrast nor phase
In dim light, phase degrades because the correlator needs signal, and contrast simply does not exist. That is what laser rangefinders are for: a VCSEL diode fires infrared pulses at around 940 nanometres and a photodiode measures how long they take to come back. It is a short-range time-of-flight sensor (up to about five metres) that locks the lens almost instantly, however dark the subject. It fails on glass —the beam goes through the window and measures the street— and on surfaces that absorb infrared. Phones with two or three rear cameras add another source of information: the disparity between lenses, the same triangulation the human eye performs, which at short distances is more reliable than any sharpness estimate.
The error margin is set by the optics, not the algorithm
Here a detail appears that explains a lot: on a small sensor, focusing error hardly matters. The admissible circle of confusion —the blur the eye cannot distinguish— is proportional to pixel size and f-number. With 1.2-micrometre pixels and an f/1.8 aperture, depth of field at one metre is barely a few centimetres, yet the system can be 20 % off and still look sharp. With a one-inch sensor and a faster lens, the same relative error shows. That is why phones with large sensors are the ones that struggle most with focus, and the ones that lean hardest on quad-pixel phase detection.
The actuator has to be precise too: modern VCMs are closed-loop, with a Hall sensor reporting the lens’s real position, so the controller corrects spring hysteresis and friction. And they share a suspension with optical stabilisation (OIS), which moves the same lens to compensate for shake. If both loops act at once without coordinating, they fight each other; the firmware separates their frequency bands: OIS keeps the low-frequency hand movement, focus keeps the fast corrections.
What happens between aiming and shooting
With the lens sorted, the decision belongs to software. The imaging pipeline produces frames at 30, 60 or 120 per second; on each one, a detector —today almost always a small convolutional neural network running on the ISP or the NPU— locates faces, eyes and, in the newest models, bodies and animals. The AF system picks the region of interest, computes phase inside it and commands the movement. If the subject moves, the phase shift between frames lets it estimate speed and lead the lens, compensating for readout and actuation lag: that is predictive autofocus.
All of that happens in a few milliseconds and explains behaviour that looks arbitrary. That the camera focuses on the window glass instead of the landscape is its preference for high, nearby contrast. That a photo in a dark concert comes out shaky is not only a lack of light: without reliable phase, the system falls back on contrast, takes its time and ends up firing with the lens halfway. And that video “breathes” —that soft sway of the framing— is the fingerprint of the loop continuously correcting a small error you would never notice in a single still.
Next time a photo comes out blurry, it is worth looking at what was in the centre of the frame: probably nothing with edges. The system did what it knows how to do, hunting for the spot where the lines look sharpest, a hundred times a second, and it did not find it.





