← CONTACT SHEET

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.

HOW PDAF PIXELS ARE PHYSICALLY MASKEDLENS APERTURE — FRONT VIEWLLEFT HALFRRIGHT HALFSENSOR — PDAF PIXEL PAIRL PIXELLeft-masked pixelreceives light from the LEFT HALF of the aperture only↑ BOTH PIXELS SIT SIDE BY SIDE ON THE SAME SENSOR ↓R PIXELRight-masked pixelreceives light from the RIGHT HALF of the aperture onlyLIGHT FROM A SUBJECT ENTERS THE ENTIRE APERTURE · MICROLENS MASKS ON EACH PIXEL DETERMINE WHAT IT SEES
Each PDAF pixel is physically masked at the sensor. The L pixel’s metal mask only passes light that arrived from the left half of the lens aperture; the R pixel sees only the right half. Both pixels sit physically adjacent on the sensor — the masking is done at the pixel level, not at the lens.
STATEPDAF PIXELSL vs R SUB-IMAGE OUTPUTINFERENCEBACK FOCUSBackFocusLEFT HALFLof the lensRIGHT HALFRof the lensLR←—— offset ——→L and R spreadapartmove closerIN FOCUSInFocusLEFT HALFLof the lensRIGHT HALFRof the lensLRalignedL and R alignedzero offsetlocked ✔FRONT FOCUSFrontFocusLEFT HALFLof the lensRIGHT HALFRof the lensLR→—— crossed ——←L and R spreadapart, crossedmove fartherPHASE OFFSET DIRECTION + MAGNITUDE ENCODES FOCUS ERROR · COMPUTED IN ONE FRAME · NO HUNTING
Phase detection reads defocus in a single frame. The shift between left-masked and right-masked pixel outputs tells the camera both direction and distance — so the lens moves directly to the correct position.

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.

LENS POSITION →BEST FOCUSLOWHIGHSHARPNESS123456overshootLOCKEDSTARTEACH STEP REQUIRES ONE FRAME · SLOW BUT ACCURATE · WORKS ON ANY SENSOR
Contrast detection steps toward maximum sharpness, overshoots slightly past the peak, then steps back to lock. Each movement requires reading a new frame — typically 10–30 frames to acquire focus from a cold start.

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.

SENSORSubjectDetectedPHASE DETECTPDAFcompute error · move once1 frame · 20–50msREFINECDAFclimb sharpness hill · fine lock3–5 frames · sub-pixel accuracyOUTPUTAF Lockedtotal: 50–100msCONTINUOUSTrackingPDAF per-frame to hold lock
Hybrid AF: PDAF moves the lens to the correct zone in a single frame. CDAF then refines within that zone with a 3–5 frame hill climb. The total acquisition time is 50–100ms — fast enough to feel instantaneous.

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.

AI TRACKING: SEMANTIC SUBJECT IDENTITY ON TOP OF PDAF GEOMETRYWITHOUT AI TRACKINGSUBJECTBACKGROUNDAF locked hereAF drifts to background when subject moves or exits frameWITH AI TRACKINGPERSON ✓ 97%AF locked ✔BACKGROUND(not targeted)neural net identity persists through motion and partial occlusion
Without AI tracking, the AF engine evaluates the full frame and may lock onto whatever is highest-contrast — often the background when the subject moves. With tracking, a neural network runs continuously, identifies the subject each frame, and passes a bounding box to the AF engine so PDAF operates only within that region.

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.