Tap on a face in your phone's camera app and it snaps into crisp focus almost instantly, while the background might stay soft. That quick, confident adjustment is the result of an autofocusThe camera feature that automatically adjusts the lens so the subject in the frame looks sharp, instead of you having to focus it by hand. More in the glossary system constantly working in the background, measuring sharpness or focus error many times per second and moving lens elements in tiny increments until the chosen part of the scene looks as sharp as the camera can make it.
Phones generally rely on one or both of two different autofocus approaches: contrast detection, which works by actively testing different focus positions and measuring how sharp the resulting image looks at each one, and phase detection, which measures the direction and amount of focus error directly using specialized points on the sensor, without needing to test multiple positions first.
Both approaches are trying to answer the same basic question as quickly and accurately as possible: in which direction, and by how much, should the lens move to make the chosen subject sharp. Understanding how each method works explains why autofocus sometimes hunts back and forth before locking on, and why modern phones with phase detection tend to focus noticeably faster than older designs relying on contrast detection alone.
What focus actually means for a lens
A lens brings light from a specific distance into sharp focus at the sensor; light from other distances arrives slightly spread out rather than converging to a crisp point, producing a softer, blurrier result for anything not at that particular focus distance. Moving lens elements closer to or farther from the sensor changes which distance is currently in sharp focus.
Autofocus is fundamentally the process of figuring out the correct lens position for the distance of whatever subject you want sharp, and then physically moving tiny motors inside the lens assembly to reach that position, all within a fraction of a second.
Contrast detection: focus by trial and measurement
Contrast detection autofocus works by examining the image the sensor is currently producing and measuring how much contrast, meaning the difference between light and dark areas, exists at fine detail edges within the chosen focus area. A perfectly sharp image shows strong, crisp contrast at edges, while a blurry image shows weaker, smeared-out contrast at the same edges.
The system moves the lens slightly, checks whether contrast at the focus area increased or decreased, and keeps moving in whichever direction increases contrast, repeating this process until contrast peaks and further movement in either direction only makes it worse. This method is reliable and does not need any special sensor hardware beyond the ability to analyze the image itself, but it is inherently a bit slower, because the system has to actively test multiple positions through trial and comparison rather than calculating the needed movement directly.
Phase detection: focus by measuring error directly
Phase detection autofocus uses special pairs of sensing points, often built directly into the main image sensor itself, that each capture light arriving from slightly different angles, similar in principle to how two eyes viewing a scene from slightly different positions can help judge distance. When the subject is in focus, these two slightly offset views line up; when the subject is out of focus, the two views are shifted apart from each other, and the amount and direction of that shift directly indicates how far out of focus the subject is and in which direction.
Because this shift can be measured directly from a single image capture, without needing to move the lens and check contrast repeatedly, phase detection can calculate the needed lens movement in essentially one step, making it considerably faster than pure contrast detection, which is why it has become the dominant approach in modern phone cameras, often paired with contrast detection for a final fine-tuning pass.
Why autofocus sometimes hunts back and forth
You may have noticed a camera occasionally moving the focus noticeably in and out before settling, a behavior often called focus hunting. This tends to happen in low light, where there is less contrast information available for contrast detection to work with, or in scenes with low detail and few sharp edges anywhere, such as a plain wall, where there is simply not much contrast signal to measure in the first place.
Phase detection systems can also struggle in certain tricky scenes, such as scenes with repeating patterns that can confuse the offset-comparison measurement, or in very low light where there is not enough light reaching the specialized focus-sensing points to get a reliable reading. Many phones automatically blend phase and contrast detection specifically to cover for each method's individual weak points.
How the camera decides where to focus
Deciding which part of a scene autofocus should prioritize is a separate question from how focus itself is measured, and phones typically use face and subject detection software to identify likely points of interest, such as a person's face or eyes, and prioritize focusing there automatically. Tapping on a specific spot in the camera app directly overrides this automatic choice, telling the system exactly which area's sharpness it should be optimizing for.
This combination, automatic subject detection plus the ability to manually tap and choose, is why phone cameras usually focus on the right thing without any input, but still allow a deliberate override for less typical compositions, like focusing on an object in the foreground while deliberately leaving a person in the background soft.
Contrast detection versus phase detection autofocus
| Aspect | Contrast detection | Phase detection |
|---|---|---|
| How it measures focus | Tests multiple lens positions and compares resulting image contrast | Compares two offset views from special sensor points in a single capture |
| Typical speed | Slower, since it tests positions through trial and comparison | Faster, since it can calculate the needed movement directly |
| Performance in low light | Can struggle when there is little contrast to measure | Can also struggle, but often more gracefully than contrast detection alone |
| Hardware needed | Works with ordinary sensor data | Requires specialized sensing points built into or alongside the sensor |
Common Mistakes
- Assuming autofocus always picks the single most interesting object in a scene correctly without any help, when subject and face detection can still be fooled by unusual compositions.
- Thinking focus hunting, where the lens visibly moves back and forth, is a camera malfunction rather than a natural result of weak contrast or difficult lighting conditions.
- Believing phase detection and contrast detection are competing, mutually exclusive technologies, when most modern phones actually combine both for speed and accuracy.
- Assuming tapping to focus only affects sharpness, when it typically also affects exposure, since the camera often uses the same tapped area to judge brightness as well.
Frequently Asked Questions
Why does my phone sometimes struggle to focus in a dark room?
Both major autofocus methods rely on having enough light and image detail to work with, so dim conditions with few sharp edges or low overall light make it harder for the system to confidently judge focus.
What does tapping to focus on the screen actually do?
It tells the autofocus system to prioritize sharpness at that specific spot rather than relying on automatic face or subject detection, and it often also adjusts exposure based on the brightness at that same spot.
Is phase detection autofocus always better than contrast detection?
It is generally faster, but contrast detection can still provide a useful fine-tuning check, which is why many phones use both methods together rather than relying on just one.
Why does the background sometimes blur when the foreground is in sharp focus?
This happens because a lens only brings one specific distance into full sharpness at a time, so anything meaningfully closer or farther than the focused distance naturally appears softer, an effect that becomes more pronounced with certain lens and aperture combinations.
Sources
- SMPTE — technical standards for imaging and media — https://www.smpte.org/
- IEEE Spectrum — explainers on camera and optical sensor technology — https://spectrum.ieee.org/
