system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How does "Auto focus" works on cameras?

Like, how can the camera decide that the object is in focus? How is the distance measured by using just light (I assume so since it's normally very difficult for the camera to focus in low light environment)
gpt
To add to the other answer that's here already with a tiny bit more detail:

The first uses infrared (IR) light, and the sensor in the camera measures the time it takes for the IR light return to figure out the distance. Fancy computer calculations that already know all the variables (lens length, aperture, etc etc) then figures out the physical distance to the target and adjusts the lens to the proper focal length. It can be confused by other sources of IR light in the room, or something interfering with the IR light coming back to the camera's sensor.

The other type works exactly as stated, looking for contrast points in the photo and then changing the focal length and looking at the same points. It compares the two results to determine which gives the clearer lines. This type of autofocus doesn't know the distance it just looks at the contrast points. It can have issues with changing lighting scenarios and moving targets because of this. This type can be slower to "hunt" for the focus sometimes, and lower light can make it harder to use as there's generally less contrast to be had.