system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How do cameras, or their lenses, auto-focus?

At first I thought that maybe the concept was a little similar to our eyes in that it tries to get as much of the incoming light on one point, the middle of the sensor, and so adjusts the focus ring until it finds a position with the largest amount of light on this spot. However, this doesn't explain (to me, anyway - maybe I'm just being thick) how a lens will be able to refocus on objects based on distance.
gpt
2 ways:

- You digitally analyze the frame to figure out the least blurry lens configuration. Least blurry means sharpest color transitions between neighboring pixels. Only works in certain types of digital cameras. 

- You measure the distance between the camera and the target, and figure out an appropriate lens configuration.  Little IR sensors can be used to measure the distance.