Math Tools Math Tools

The Math Behind GPS: How Your Phone Knows Where You Are

The Math Behind GPS: How Your Phone Knows Where You Are

By Math Tools ·

The Math Behind GPS: How Your Phone Knows Where You Are

Your phone never sends anything to a GPS satellite. It only listens. From a handful of faint radio signals that left orbit about 67 milliseconds earlier, it works out where you are to within a few meters.

The secret is that GPS isn't really a location system. It's a timing system. Every meter of accuracy comes from measuring time to within billionths of a second. And without a correction from Einstein's theory of relativity, the whole thing would drift off by about 11 kilometers a day.


You Need Four Satellites to Find Three Coordinates

Your position has three unknowns: latitude, longitude and altitude (or x, y, z). So three satellites should be enough, right?

Not quite. Each satellite carries an atomic clock that's accurate to a few billionths of a second. Your phone's quartz clock is nowhere near that good. That clock error is a fourth unknown, so the receiver has to solve for four values, and that takes four equations, one per satellite:

(x − x₁)² + (y − y₁)² + (z − z₁)² = (c · (t₁ − t_bias))²
(x − x₂)² + (y − y₂)² + (z − z₂)² = (c · (t₂ − t_bias))²
(x − x₃)² + (y − y₃)² + (z − z₃)² = (c · (t₃ − t_bias))²
(x − x₄)² + (y − y₄)² + (z − z₄)² = (c · (t₄ − t_bias))²

Here (xᵢ, yᵢ, zᵢ) is where satellite i was when it sent its signal, tᵢ is the measured travel time, and c is the speed of light. Solve for x, y, z and t_bias, and you know where you are and what time it is.


Step 1: Distance From Time

Each GPS satellite continuously broadcasts its position and the exact time the message was sent. Your receiver notes when the message arrives. Multiply the travel time by the speed of light (299,792,458 m/s) and you get a distance:

distance = c × Δt

Satellites orbit at about 20,200 km above Earth, so the signal takes roughly 67 milliseconds to arrive. The precision needed is extreme:

1 nanosecond × 299,792,458 m/s ≈ 0.30 meters

A one-billionth-of-a-second error moves you 30 cm. A one-millisecond error would put you 300 km away.


Step 2: Trilateration

Knowing your distance from one satellite puts you somewhere on a sphere around it. Two spheres intersect in a circle. A third sphere cuts that circle down to two points, and usually one of them is far out in space or deep inside the Earth. This is trilateration: locating a point from distances, not angles. (Measuring angles is triangulation.)

The equations above are just the 3D version of the distance formula from analytic geometry:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Because the equations are nonlinear (they contain squares), receivers typically solve them iteratively. They start with a guess, linearize the equations around it, solve a small matrix system with least squares, and repeat until the answer converges. It usually takes only a few iterations.


Step 3: Einstein's Correction

Here's where GPS gets truly remarkable. Two effects from relativity change how fast the satellite clocks tick compared with clocks on the ground:

  • Special relativity: satellites move at about 2.6 km/s, so their clocks run slow by about 7 microseconds per day.
  • General relativity: satellites sit higher in Earth's gravity well, where time runs faster, so their clocks run fast by about 45 microseconds per day.

The net effect is that satellite clocks gain about 38 microseconds per day. Multiply by the speed of light:

38 × 10⁻⁶ s × 299,792 km/s ≈ 11.4 km

Uncorrected, position errors would build up by roughly 11 km every day. Engineers solved this by deliberately setting the satellite clock frequency slightly low before launch, so the clocks tick at the right rate once in orbit. Relativity isn't just a theory to GPS. It's a line in the engineering spec.


Step 4: Converting to Latitude and Longitude

The receiver's solution comes out in Earth-Centered, Earth-Fixed (ECEF) Cartesian coordinates, with the origin at Earth's center. To show you a map, it converts x, y, z to latitude, longitude and height on a reference ellipsoid called WGS 84.

Earth isn't a sphere. It's slightly flattened, with an equatorial radius of 6,378.137 km and a polar radius about 21 km smaller. That conversion uses trigonometry: inverse tangents for longitude and an iterative calculation for latitude. You can practice the basic idea with the polar-rectangular converter and the degrees-minutes-seconds converter.


An Insider Reference: Gladys West

The GPS program was led by U.S. Air Force Colonel Bradford Parkinson, often called the "father of GPS," with the first satellite launched in 1978. But one of the key mathematical contributions came from Gladys West, a mathematician at the Naval Surface Warfare Center in Dahlgren, Virginia.

Starting in the 1970s and into the 1980s, West programmed computers to build increasingly precise models of the geoid, the true lumpy shape of Earth's gravity field. Those models underpin the accuracy of satellite geodesy and GPS. She was inducted into the U.S. Air Force Space and Missile Pioneers Hall of Fame in 2018.


Two Concepts Worth Knowing

Dilution of Precision

Satellite geometry matters. If all visible satellites are bunched together in one part of the sky, small timing errors cause large position errors. Receivers compute Dilution of Precision (DOP) from the geometry matrix. Satellites spread widely across the sky give a low DOP and a better fix.

Least Squares

Receivers usually see 8 to 12 satellites, more than the 4 required. With more equations than unknowns, they use least squares to find the position that minimizes the total squared error across all measurements. It's the same method behind linear regression.


Quick Answer: How Does GPS Work Mathematically?

A GPS receiver measures how long signals take to arrive from at least four satellites, converts each time into a distance using the speed of light, and solves four equations for its three position coordinates plus its own clock error. Relativity corrections of about 38 microseconds per day keep it accurate.


Try Them Yourself

Open your phone's map, note your coordinates, and convert them to degrees, minutes and seconds. Every digit there comes from solving four equations in a few milliseconds.