How Autofocus Works: Phase Detection, Contrast Detection, and AI Tracking
Phase detection reads where focus is in one shot. Contrast detection climbs a sharpness hill. AI tracking knows what you're pointing at. Here's how all three work — and why your camera still misses.
The lens snap you hear when you half-press the shutter is mechanical. The computation that decided exactly where to stop it happened in single-digit milliseconds, before the motor even began moving.
Modern autofocus systems lock a subject in 50–100ms, track it across the frame, and recover when it disappears behind an obstacle. Understanding how changes how you shoot — and what you should actually care about when buying a camera.
What Focus Actually Means
A lens focuses by moving a glass element so that the cone of light from a subject converges to a point exactly on the sensor plane. Move the element too close or too far and the cone either hasn’t converged yet (front focus) or has already converged and started diverging again (back focus). Both produce blur.
The autofocus system’s only job is to find the lens position where convergence lands precisely on the sensor. There are two fundamentally different approaches to solving that problem.
Phase Detection: Getting There in One Shot
Phase detection works by splitting the light that passes through the lens into two sub-images using paired pixels on the sensor. Each pixel in a PDAF pair is masked: the L pixel only receives light from the left half of the lens aperture, the R pixel only from the right half.
When the lens is in focus, the two sub-images align. When the lens is out of focus, they shift apart — the direction and magnitude of that shift encodes both where focus is and exactly how far the lens needs to move.
This is phase detection autofocus (PDAF). The critical advantage: it requires exactly one sample to compute the answer. There is no hunting, no trial movement, no feedback loop. The camera reads the phase error, multiplies by a calibration constant, and sends a move command to the lens motor.
On a smartphone, PDAF pixels are embedded directly into the imaging sensor — typically scattered throughout the Bayer array or arranged in dedicated rows. The sacrifice is tiny: those pixels read from half the lens aperture, so they contribute slightly less to the final image. In practice it’s invisible.
Contrast Detection: The Hill Climber
Contrast detection autofocus (CDAF) takes the opposite approach. It has no geometric insight into focus error. Instead, it measures sharpness — specifically the high-frequency contrast in a region of the frame — and moves the lens to maximize that value.
The sharpness curve over lens position looks like a hill with a single peak at best focus. CDAF climbs that hill by moving the lens in small steps, reading sharpness at each position, and continuing in whichever direction sharpness increases.
The drawback is intrinsic to the algorithm: each step requires capturing and reading a new frame. From a cold start, CDAF typically takes 10–30 frames to reach best focus. At 30fps that’s 330ms–1 second — perceptibly slow for anything that moves.
CDAF does have one genuine advantage over PDAF: it works on any sensor, needs no dedicated pixels, and its final lock precision is excellent because it directly maximizes the thing you actually want — sharpness.
Hybrid AF: How Modern Cameras Use Both
Contemporary cameras rarely use either algorithm in isolation. They combine them into a two-stage pipeline: PDAF for fast coarse acquisition, CDAF for precise final lock.
The result: fast acquisition that doesn’t feel like hunting, followed by a final lock with the precision you’d normally associate with slower systems. This is why flagship phones and mirrorless cameras report sub-100ms AF speeds that would have seemed impossible with pure CDAF.
AI Tracking: Adding Subject Awareness
Phase and contrast detection are purely geometric. They measure where in the scene has the highest contrast or phase alignment — but they have no understanding of what they’re focusing on.
AI tracking adds a semantic layer on top of the geometry. A neural network running on the camera’s vision processor identifies subjects — faces, eyes, bodies, vehicles, birds — and passes their bounding boxes to the AF engine as target regions. The AF system then uses PDAF within those regions rather than the full frame.
The practical effect is dramatic. With subject tracking disabled, an AF system might lock on the background when a person steps partially out of frame. With tracking enabled, it continues to prioritize the person even under partial occlusion, rapid motion, or poor light — because the neural network maintains a semantic identity for the target, not just a pixel cluster.
This is also where the meaningful differentiation between flagship and mid-range cameras actually lives. Sensor PDAF density is similar across price tiers at this point. What differs is the quality of the subject detection model and the computational budget allocated to running it continuously at full frame rate.
Why Autofocus Still Fails
Understanding the algorithms makes the failure modes predictable.
Low contrast scenes fail CDAF — a flat-colored wall gives the hill climber no gradient to follow. Many cameras will hunt indefinitely on low-texture subjects.
Low light fails PDAF — phase detection relies on signal level. Below a threshold, the phase difference between L and R pixels drops below the noise floor. Most cameras fall back to CDAF (slower) or give up entirely.
Small, fast subjects break AI tracking — the neural network needs enough pixels to classify a subject. A small bird at the edge of the frame, or a subject moving fast enough that its bounding box jumps between frames, can cause the tracking logic to drop and re-acquire repeatedly.
Reflective and low-contrast surfaces — glass, mirrors, and flat-colored subjects confuse both phase and contrast approaches. This is not a software problem — it’s a geometry problem.
Knowing the failure mode tells you the workaround: switch to manual focus or manual focus assist for static low-contrast subjects; use face/eye detection rather than subject tracking for humans; pre-focus on a spot for predictable fast motion.
What This Means When Buying
For smartphones, PDAF density on the sensor and AI tracking quality matter far more than megapixel count. A phone with dedicated PDAF rows across the full sensor will consistently outperform one with scattered PDAF clusters, especially in video.
For mirrorless cameras, the claimed AF acquisition speed is less useful than knowing whether the subject tracking uses a dedicated processor. A camera that runs its subject detection at 30fps on a dedicated neural accelerator will track differently under real conditions than one processing at 15fps on the main CPU. Those numbers rarely appear in spec sheets — look for real-world tracking tests instead.
The mechanical part of autofocus — the motor driving the lens — is now rarely the bottleneck. The algorithms and the silicon running them are.