As discussed in our ‘Finding Satellites’ page, each satellite in the GPS constellation transmits a unique C/A code, which appears to be random noise, but is in fact a deterministic sequence. Because the sequence is deterministic, a GPS receiver has the ability to generate exactly the same sequence of code as the satellite itself. By generating the same pattern internally, the receiver looks for the pattern being transmitted by the satellite, then works out how much of a delay there is compared to its own pattern.
It can do this because of the accurate clock synchronisation. For instance, imagine you and a friend are stood in a very large field. You synchronise your watches and your friend agrees to fire a starting pistol at exactly midday. Your friend then walks off to the other end of the field. At precisely midday, they fire the pistol, but according to your watch, you don’t hear the bang until four seconds after mid-day because the sound had to travel across the field. If we assume the speed of sound is 340 m/s, we can multiply that by the time taken work out that your friend is 1,360 metres away.
The receiver and GPS satellite work in a similar way. Because the receiver is able to accurately synchronise its clock with those of the satellites, and because it knows what the time was when the speed by the time taken to work out how far away the satellite is.
There are other factors it needs to take into account of course, but that is the underlying principal.