---
title: "How Does GPS Work? Trilateration, Clocks and Relativity"
description: "How GPS finds your location: distance from signal timing, trilateration in Python, why four satellites are needed, and the relativity correction."
slug: how-does-gps-work
canonical: https://learn.modernagecoders.com/blog/how-does-gps-work/
date: 2026-09-28
dateModified: 2026-09-28
category: "Mathematics"
tags: ["GPS", "Physics", "Python", "Equations"]
keywords: ["how does gps work", "how does gps work for kids", "trilateration", "how many satellites does gps need", "gps relativity", "how gps calculates position", "gps explained simply"]
readTime: "8 min read"
author: "Modern Age Coders Team"
---
# How Does GPS Work? Trilateration, Clocks and Relativity

> Distances from timing, positions from circles, why four satellites are needed, and why Einstein matters to the blue dot on your map, with the maths done in Python.

![How GPS works: three satellites sending signals down to a point on the Earth's surface](/images/blog/how-does-gps-work/00-hero.png)

*By Modern Age Coders Team · 2026-09-28 · 8 min read*

**Quick answer:** GPS satellites broadcast their position and the exact time. Your phone measures how long each signal took, multiplies by the speed of light to get distances, and finds the one place that is those distances from several satellites, a method called trilateration. Timing must be precise: a one microsecond error means about 300 m. Your phone solves for its own clock error too, so it needs at least four satellites. Satellite clocks gain about 38 microseconds a day from relativity, about 11 km a day of error if uncorrected.

Open a map on your phone and a blue dot shows where you are, usually to within a few metres. There is no signal from your phone to space, and the satellites do not know you exist. Your phone works out its own position by listening to satellites more than 20,000 km overhead and timing how long their signals take to arrive.

This guide explains how that works, step by step: distances from timing, finding a position from distances (called trilateration), why tiny clock errors matter so much, and why Einstein's relativity has to be built into the system. A short Python program does the same calculation your phone does, in two dimensions.

## The satellites

The Global Positioning System, run by the United States, has around 31 operational satellites orbiting at a height of about 20,180 km, each going round the Earth in just under 12 hours. They are arranged so that almost anywhere on Earth, several are above the horizon at any time. Each carries very precise atomic clocks and continuously broadcasts its position and the exact time the signal left it. Other countries run similar systems, such as Europe's Galileo, and most phones use several at once.

## Step 1: distance from time

Radio signals travel at the speed of light, 299,792,458 metres per second. If your phone knows when a signal left the satellite and when it arrived, it can work out the distance: distance = speed × time. A signal that took 0.07 seconds came from about 21,000 km away. But this means the timing has to be astonishingly accurate:

**timing.py**

```python
c = 299_792_458          # speed of light in metres per second

for name, seconds in [("1 nanosecond", 1e-9), ("1 microsecond", 1e-6), ("1 millisecond", 1e-3)]:
    print(f"a clock error of {name:<14} -> {c * seconds:>12,.1f} m of distance error")

# satellite clocks run fast by about 38 microseconds a day (relativity)
print(f"38 microseconds a day uncorrected -> {c * 38e-6 / 1000:.1f} km a day")
```

**Output**

```text
a clock error of 1 nanosecond   ->          0.3 m of distance error
a clock error of 1 microsecond  ->        299.8 m of distance error
a clock error of 1 millisecond  ->    299,792.5 m of distance error
38 microseconds a day uncorrected -> 11.4 km a day
```

![Clock errors turned into distance: 1 nanosecond gives 0.3 metres, 1 microsecond 299.8 metres, 1 millisecond 299,792.5 metres; relativity's 38 microseconds a day would add about 11.4 km a day](/images/blog/how-does-gps-work/02-timing.png)

*Every nanosecond counts.*

An error of just one millionth of a second puts you 299.8 m out. That is why the satellites carry atomic clocks, and why the fourth satellite in the next section matters so much.

## Step 2: position from distances (trilateration)

Knowing you are exactly 5 km from one tower does not tell you where you are: you could be anywhere on a circle of radius 5 km around it. A second distance narrows it to the two points where two circles cross. A third picks the right one. This is **trilateration**, and here it is in two dimensions, with three towers and a phone at a secret position:

**trilat.py**

```python
import math

# Three towers at known positions (in km) and a phone somewhere between them
towers = [(0, 0), (10, 0), (4, 8)]
true_position = (6, 3)
distances = [math.dist(t, true_position) for t in towers]
if __name__ == "__main__":
    print("measured distances:", ", ".join(f"{d:.3f} km" for d in distances))

def locate(towers, d):
    """Subtract the circle equations to get two straight-line equations, then solve."""
    (x1, y1), (x2, y2), (x3, y3) = towers
    a1, b1 = 2 * (x2 - x1), 2 * (y2 - y1)
    c1 = d[0]**2 - d[1]**2 - x1**2 + x2**2 - y1**2 + y2**2
    a2, b2 = 2 * (x3 - x1), 2 * (y3 - y1)
    c2 = d[0]**2 - d[2]**2 - x1**2 + x3**2 - y1**2 + y3**2
    det = a1 * b2 - a2 * b1
    return (c1 * b2 - c2 * b1) / det, (a1 * c2 - a2 * c1) / det

if __name__ == "__main__":
    x, y = locate(towers, distances)
    print(f"position found: ({x:.3f}, {y:.3f})")
```

**Output**

```text
measured distances: 6.708 km, 5.000 km, 5.385 km
position found: (6.000, 3.000)
```

![Trilateration: three circles centred on three towers, with radii equal to the measured distances, all cross at the phone's position (6, 3)](/images/blog/how-does-gps-work/01-circles.png)

*One distance gives a circle. Three give a point.*

The neat trick in `locate` is that subtracting one circle's equation from another cancels the x² and y² terms, leaving a straight-line equation. Two such lines give two ordinary [simultaneous equations](/blog/how-to-solve-simultaneous-equations), which the last three lines solve. The program recovers the position exactly. In three dimensions, circles become spheres, but the idea is identical.

## Real measurements are never perfect

Signals are slowed slightly by the atmosphere, bounce off buildings and arrive a little late. So in practice each distance is a bit wrong. We added errors of 100 to 300 metres to the three distances:

**noise.py**

```python
import math
from trilat import towers, true_position, distances, locate

errors = [0.2, -0.3, 0.1]                 # each distance off by a few hundred metres
noisy = [d + e for d, e in zip(distances, errors)]
x, y = locate(towers, noisy)
print(f"with noisy distances: ({x:.3f}, {y:.3f})")
print(f"off by {math.dist((x, y), true_position) * 1000:.0f} m")
```

**Output**

```text
with noisy distances: (6.282, 2.961)
off by 284 m
```

![With distance errors of a few hundred metres, the three circles no longer meet at one point; the calculated position is 284 metres from the true one](/images/blog/how-does-gps-work/03-noise.png)

*Errors in the inputs become errors in the answer.*

Now the three circles do not meet at a single point, and the calculated position is 284 m from the truth. Real receivers use more satellites than the minimum and combine all the measurements in a best-fit calculation, which averages out much of the error. That is one reason your position is usually far better than this toy example.

## Why the positions of the satellites matter

Trilateration works best when the reference points are spread out. Put the three towers in a straight line and something strange happens: a point above the line and its mirror image below it are exactly the same distances from all three.

**line.py**

```python
import math
from trilat import locate

# Three towers in a straight line: a phone above the line and its mirror image below
towers = [(0, 0), (5, 0), (10, 0)]
above, below = (6, 3), (6, -3)
print("distances from above:", [round(math.dist(t, above), 3) for t in towers])
print("distances from below:", [round(math.dist(t, below), 3) for t in towers])
try:
    locate(towers, [math.dist(t, above) for t in towers])
except ZeroDivisionError:
    print("locate() fails: the equations cannot tell the two points apart")
```

**Output**

```text
distances from above: [6.708, 3.162, 5.0]
distances from below: [6.708, 3.162, 5.0]
locate() fails: the equations cannot tell the two points apart
```

> **Satellite geometry**

> The same thing happens, more gently, with satellites. When the satellites your phone can see are bunched together in one part of the sky, small timing errors turn into much bigger position errors. When they are spread across the sky, the circles cross at sharp angles and the position is much more precise. Receivers take this into account when choosing which satellites to use.

## Why four satellites, not three

Your phone does not have an atomic clock. Its clock is cheap and can be off by far more than a microsecond, which on its own would ruin every distance. The solution is elegant: treat the phone's clock error as an unknown to solve for, alongside the three coordinates of your position.

![Four unknowns in GPS: x, y and z for position and t for the phone's clock error, which is why at least four satellites are needed](/images/blog/how-does-gps-work/04-four.png)

*The phone solves for its own clock error.*

Four unknowns need four equations, so a receiver needs signals from at least four satellites. With four or more, it can work out both where it is and exactly what time it is. This is why GPS is also used to synchronise clocks in phone networks and power grids.

## The relativity correction

Here is the part that surprises most people. According to Einstein's theories of relativity, clocks moving fast run slow, and clocks in weaker gravity run fast. The satellites are moving at several kilometres per second, which slows their clocks, but they are far from Earth's gravity, which speeds them up more. Overall, the satellite clocks gain about 38 microseconds a day compared with clocks on the ground. From the timing table, that would add up to roughly 11.4 km of error every day if nobody corrected for it. The system is designed with the correction built in, so relativity is not just theory: it is part of every map you open.

## GPS in your phone, today

- **Several systems at once:** most phones combine GPS with Galileo, GLONASS and BeiDou, so there are more satellites to use.
- **Help from the network:** phones use nearby Wi-Fi and mobile masts to get a first rough fix quickly.
- **Indoors and in cities:** signals are blocked or bounce off buildings, which is why the blue dot sometimes jumps around.
- **One-way:** your phone only receives. The satellites never know you are there.

> Your phone finds itself by timing light, solving simultaneous equations and allowing for relativity, many times a second.

## How we teach it

GPS is a good example of a principle on our [how we teach](/how-we-teach) page: learning by building. Coding trilateration yourself turns circles, distances and simultaneous equations into something you can see working, and students explain their thinking as they connect each step to the maths behind it. Our [live maths classes](/online-maths-tuition) and coding courses run one to one or in small groups of 5 to 10.

[Book a free class](/book-demo) [Book a priority demo](/book-demo)

## Frequently asked questions

**How does GPS work in simple terms?**

Satellites broadcast their position and the exact time. Your phone measures how long each signal took to arrive, turns that into a distance using the speed of light, and works out where it must be to be those distances from several satellites. This is called trilateration.

**How many satellites does GPS need?**

At least four. Three give your position in three dimensions, and the fourth lets the receiver correct its own clock, which is not accurate enough on its own. More satellites improve accuracy.

**What is trilateration?**

Finding a position from distances to known points. One distance puts you on a circle or sphere; combining three or more narrows it down to a single point where they all meet.

**How high are GPS satellites?**

About 20,180 km above the Earth, orbiting roughly twice a day. The system has around 31 operational satellites.

**Does GPS use data or send my location?**

GPS itself only receives signals and sends nothing. Apps on your phone may use the location they calculate and send it over the internet, which is a separate matter.

**Why does GPS need relativity?**

Because the satellite clocks gain about 38 microseconds a day relative to clocks on the ground, due to their speed and weaker gravity. Uncorrected, this would build up to around 11 km of position error per day.

**Why is GPS less accurate indoors or in cities?**

Signals are blocked by roofs and walls, and in cities they bounce off buildings and arrive late, which makes the distances wrong. Phones use Wi-Fi and mobile masts to help in these places.

---

*Source: https://learn.modernagecoders.com/blog/how-does-gps-work/*
