
When I open the map on my phone in Munich, the little blue dot sits on the correct side of the street. I know, nothing special. But I’d read somewhere that this only works because of Einstein, and I realised I had never actually checked the numbers. So one evening I sat down with the papers and a Python shell.
Spoiler: it’s true, and the numbers are surprisingly easy to reproduce.
How GPS finds you, in short
The GPS system has a constellation of satellites at about 20,200 km above the Earth. Each of them carries atomic clocks and keeps sending out two things: “this is the time on my clock” and “this is where I am”. Your phone listens to at least four of them.
Radio signals travel at the speed of light. If the signal from one satellite took 0.07 seconds to arrive, you are about 21,000 km away from it. With distances to four satellites, the receiver can work out its position in three dimensions plus its own clock error. That is the whole trick: positioning is really timekeeping.
And here is the catch. Light travels about 30 cm in one nanosecond. So a clock error of one microsecond already means roughly 300 metres of distance error. The clocks have to be good. Very good.
Two effects that pull in opposite directions
When I first read about this, I was like, wait, relativity is for black holes and spaceships, not for my phone. But a GPS satellite is exactly a fast clock in a weaker gravity field, so both of Einstein’s theories apply.
Special relativity: moving clocks run slow
The satellites move at almost 4 km per second. Compared to a clock on the ground, a moving clock ticks a little slower. Think of it like this: the faster you move through space, the less of your “time budget” is left for moving through time. For GPS that comes to about 7 microseconds per day that the satellite clock falls behind.
General relativity: clocks higher up run fast
Gravity also slows time down. A clock deep in the Earth’s gravity, on the ground, ticks slower than a clock high above it. The satellites are far up, where gravity is weaker, so their clocks run faster by about 45 microseconds per day.
Put both together and the satellite clock gains about 38 microseconds every day. That doesn’t sound like much. Multiply by the speed of light, and it’s more than 11 km of error per day, growing every day. Without the correction, the blue dot would be in the next village by evening.
Calculate it yourself
This is the part I enjoyed most. You don’t need anything fancy. Here are a few lines of Python with a simple model: a circular orbit and the usual weak-field approximations from the textbooks. Let’s say we compare a satellite clock to a clock at the Earth’s mean radius and ignore the Earth’s rotation.
import math
GM = 3.986004418e14 # Earth's gravitational parameter, m³/s²
c = 299_792_458 # speed of light, m/s
earth = 6_371_000 # mean Earth radius, m
orbit = earth + 20_200_000
day = 86_400
v = math.sqrt(GM / orbit) # circular orbit speed
special = -v**2 / (2 * c**2) * day # moving clock runs slow
general = GM * (1 / earth - 1 / orbit) / c**2 * day # higher clock runs fast
print(f"speed {v / 1000:.2f} km/s")
print(f"special rel. {special * 1e6:+.1f} µs/day")
print(f"general rel. {general * 1e6:+.1f} µs/day")
print(f"net {(special + general) * 1e6:+.1f} µs/day")
print(f"distance error {(special + general) * c / 1000:.1f} km/day")Running it gives:
speed 3.87 km/s
special rel. -7.2 µs/day
general rel. +45.7 µs/day
net +38.5 µs/day
distance error 11.5 km/dayNice, right? The real values in the literature are about −7 and +45, net 38 microseconds per day, and my toy model lands right there. The distance error is a bit simplified, because the receiver also solves for its own clock offset, but it shows how fast things go wrong.
How the engineers fixed it
The solution is almost funny in how simple it is. The satellite clocks are tuned a little slow before launch. The nominal frequency of the GPS clock is 10.23 MHz, and the satellites are set to 10.22999999543 MHz instead. Once in orbit, relativity speeds them up, and from the ground they look exactly right.
That handles the constant part. The orbits are slightly elliptical though, so the satellite is sometimes a bit higher and slower, sometimes lower and faster. That periodic effect is a few tens of nanoseconds and is corrected in the receiver with a small formula. ESA’s Navipedia, linked below, shows it. There are even smaller effects, like the Sagnac effect from the Earth’s rotation, which the receiver also takes care of.
Neil Ashby’s review paper is the classic source for all of this, and it is free to read. I didn’t understand every equation, honestly. But the summary tables are very clear.
What this means for people who build software
Most of us will never write a GNSS receiver. Still, a few things from this stuck with me.
First, “what time is it?” is never a simple question. In GPS the answer depends on where the clock is and how fast it moves. On our servers it depends on NTP, on the time zone of the PHP process, on the database server’s own clock. I have seen enough bugs from a server that was a few minutes off, especially with tokens that expire, cron jobs and scheduled posts like the ones on this blog.
Second, small errors that grow every day are the dangerous ones. A 38 microsecond drift looks harmless on day one. A log table that grows by a little every hour also looks harmless on day one.
Third, the fix was not clever code but good modelling up front. The team knew the physics and adjusted the clocks before launch. In our world that is the boring design work before the first commit. I’m not a big fan of meetings, but I’m a fan of that.
What is still open
GPS works, so the big questions here are answered. But clocks keep getting better. Optical atomic clocks are now so precise that they can see the difference in time between two tables in the same lab at different heights. That opens up new ideas, like measuring height differences on the Earth using clocks, and researchers are working on it.
Also, GPS is not alone anymore. Europe’s Galileo, Russia’s GLONASS and China’s BeiDou all deal with the same relativity, each with their own clock designs. Your phone very likely uses several of them at once.
Next time your map shows you on the right side of the street, you can smile a bit. Einstein is in there. Cheers!
Further reading
- Neil Ashby: Relativity in the Global Positioning System (Living Reviews in Relativity)
- Relativistic clock correction (ESA Navipedia)
- GPS.gov, the official U.S. government information about GPS