When you press the shutter and the picture comes out sharp, the phone has solved two unknowns in a few dozen milliseconds: which way to move the lens group and by how much. The second is arithmetic. The first is the hard one. An image sensor only measures light intensity: it has no idea whether the subject sits in front of or behind the plane of focus, and without that information any correction is a guess. Systems that guess are called contrast-detection systems, and they are responsible for the familiar hunting: the lens runs back and forth, the image blurs, sharpens, blurs again, until overall contrast stops rising.
Contrast is a hill with no map
The contrast method treats the image as a signal and looks for its peak. It defines a sharpness metric — usually the sum of differences between neighbouring pixels, or the high-frequency content of a transform — and steps the focus. If the metric rises, keep going the same way; if it falls, reverse and shorten the step. It is a hill-climbing search: it works, it is cheap and it needs no special optics, but every measurement requires moving the lens and reading the sensor again. On a long-travel lens that means ten or fifteen reads, and in low light or low contrast — a blank wall, fog, a night sky — the hill flattens out and the system never finds the top.
Phase detection skips the trial and error because it measures the focus error in a single read, and it also measures its sign. The idea comes from manual-focus SLRs, where a mirror diverted part of the light to a module with separator lenses and two small linear sensors. Each sensor looked at the lens from a different edge of the exit pupil — the aperture as seen from the sensor plane — so each received an image of the subject from a slightly different perspective. With the subject at the focal plane, both images coincide pixel for pixel. Defocused one way, they separate in one direction; the other way, in the opposite one. The separation is proportional to the focus error and the sign gives the direction: a single measurement tells you how much to correct and which way.
From the mirror to the pixel itself
Moving that to a phone meant putting the pair of viewpoints inside the sensor. The most widespread technique is masked pixels: beneath a pixel’s microlens sit two photodiodes, and a thin opaque layer covers the left or right half of the aperture. One pixel sees only the left side of the pupil; its neighbour, only the right. Comparing the two signals yields the disparity. The price is twofold: those pixels lose nearly half their light, and their colour value has to be interpolated from neighbours, which leaves small artefacts in fine detail and forces the processor to tell normal pixels from phase pixels when rebuilding the Bayer mosaic.
The next generation dropped the mask. In dual-pixel sensors, each microlens covers two side-by-side photodiodes that collect light across the whole pixel: no signal loss and focus that works over 100 % of the surface, not on a sparse grid. The trick is that each photodiode still sees one half of the pupil, so their sum gives the image pixel and their difference gives the phase measurement. That same difference, summed across the frame, produces a depth map the software later uses for artificial background blur: portrait-mode bokeh is not a mask drawn by hand, it is geometry measured by the sensor.
The newest modules go one step further: instead of two photodiodes per microlens, they place one microlens over each 2×2 block of pixels and split the pupil into four quadrants. That architecture — known as 2×2 OCL, for on-chip lens — captures more light per area and lets the system compare not just left and right but also up and down, which improves focus on horizontal subjects and in dim conditions. The trade-off is that phase information exists only in blocks, at lower spatial resolution, and that processing must rebuild colour from more complex filter patterns, common in high-resolution sensors with merged pixels.
Moving the lens without overshooting
Measuring is not focusing. The typical actuator in a camera module is a voice-coil motor: a permanent magnet attached to the lens barrel, a fixed coil and a pair of springs that keep the assembly centred. When current flows, the Lorentz force shifts the barrel along its axis over a travel of barely one to three hundred microns. Sealed lenses include a Hall sensor that reads the real position, so the loop is not blind: a position is requested, checked and corrected. The same magnets and coils drive optical stabilisation, which shifts the group perpendicular to the axis; that is why a knock or a tremor can blur the frame even when the phase measurement is right, and why modern systems co-ordinate both loops before firing.
In very thin modules, where a magnet will not fit, makers turn to shape-memory alloy actuators: a wire that contracts when heated by a small current and drags the lens along. They are slower and more temperature-sensitive, but they take a fraction of the volume. The practical consequence is that focus time depends not only on the algorithm but on the mass to be moved and the force available to stop it without oscillating.
What the algorithm adds
With a phase measurement available, firmware can afford luxuries contrast never allowed. In video, the system does not focus each frame from scratch: it estimates the subject’s trajectory and predicts it with a filter, so the lens is already in place when the next frame arrives. In low light, where disparity turns into noise, an infrared time-of-flight emitter or a laser pattern steps in to measure distance independently and act as a hint. And point selection — recognising a face, an eye, a dog — does not change how defocus is measured, only which region the disparity is computed over. That detail explains why two phones with the same sensor can focus very differently: the difference lies in processing and in how much trust each maker places in each source.
Some physical limits no algorithm escapes. Phase-detection accuracy is on the order of the lens’s depth of field, so at wide apertures and with large sensors the measurement gets you close while fine adjustment still falls to contrast. Diffraction sets a minimum on the pupil size that can be split. And in low light, the signal-to-noise ratio of two pupil halves is worse than that of the full pixel: below a certain threshold the phone behaves like an old camera again, moving the lens and hoping contrast shows up. Next time a shot lands sharp instantly, remember the credit is not a faster lens but a sensor able to look at the world from two places at once.






