How it works

How Your Phone Knows Where You Are: GPS, Wi-Fi and Cell Towers

A satellite 20,000 km up sends the time. Your phone turns the delay into a spot on the map, until you walk inside.

Four glowing satellites send dashed lines down to a bright dot on the curve of the Earth, drawn in neon on black.

You come out of a station in a city you do not know. The map shows a blue dot with a pale circle around it. The dot is on the street behind you. You walk ten steps and it jumps to the right place. Later, in a shopping centre, it puts you in the car park.

Same phone, same app. What changed is what the phone could hear. This post follows the dot from a satellite to your screen and shows where each step goes wrong.

Short version:

  • GPS is a stopwatch. Each satellite says when it sent a message. The phone measures how late it arrived and multiplies by the speed of light. It needs four satellites, because the fourth lets it find its own clock error too.
  • The signal is very faint and it bounces. Inside buildings and between tall ones, the phone leans on Wi-Fi routers and cell towers that sit in a database, and blends everything into one guess.
  • The pale circle is the phone admitting it is unsure. On Android it is a 68% circle, so about one time in three you are outside it. NIST tested phones in five buildings. In four, the average miss was 16 to 33 m. In the underground one, neither phone gave a usable fix.

Four places a position can come from

A phone does not use one method. It uses whatever it can hear:

SourceWhat the phone listens toWorks bestFails when
GPS and other satellite systemsRadio from satellites about 20,000 km upOutside, with a view of the skyWalls, roofs, tall buildings
Wi-FiNames (IDs) of nearby routersWhere many routers are mappedFew routers, or a moved router
Cell towerThe tower it is already talking toAlmost everywhereAlways a wide circle
Other sensorsAir pressure, compass, BluetoothAs a hint to the restThey cannot find a place alone

Apple’s support page lists “cellular, Wi-Fi, Global Positioning System (GPS) networks, and Bluetooth” as the things Location Services can use. The sections below take them one at a time, starting with the one that sounds like magic.

GPS: a stopwatch, not a compass

GPS is the name of the American satellite system. Other countries run their own (Russia’s GLONASS, Europe’s Galileo, China’s BeiDou), and a phone can listen to several. I will say “GPS” for all of them.

The idea is simple. Every satellite carries an atomic clock and keeps repeating a message. The message says where the satellite is and when it sent the message. The GPS standard lists the contents: the time of transmission, the satellite’s position, its health, its clock correction and some corrections for the atmosphere.

Radio travels at the speed of light, about 300,000 km per second. So the delay tells you the distance.

A GPS satellite sends its position and send time. The phone times the arrival: a 70 millisecond delay at the speed of light is about 21,000 km. One millisecond of error is 300 km, one microsecond 300 m.

Some numbers, so the scale is clear. The satellites orbit about 20,200 km above the ground (Ashby’s review gives the orbit’s semi-major axis, 26,561.75 km from the centre of the Earth, and I took off the Earth’s radius). A signal from a satellite straight overhead takes about 67 ms. One near the horizon takes about 86 ms. Those two figures are my arithmetic.

Now the hard part. At 300 km per millisecond, a timing mistake of one microsecond (a millionth of a second) is 300 m. A mistake of one nanosecond is 30 cm. Ashby’s review says the same: a one nanosecond timing error leads to a position error of the order of 30 cm. A phone that wants 5 m accuracy has to think in nanoseconds. It does not have an atomic clock.

Why the phone needs four satellites

A phone has a cheap quartz clock, like the one in a watch. It is never exactly in step with the satellites. If it is off by a little, every distance it measures is wrong by the same amount. Engineers call these distances pseudoranges, “fake distances”, for that reason.

Picture it on a flat map. Each distance is a circle around a satellite: “I am this far from here”. With a perfect clock, three circles meet at one point. With a wrong clock, every circle is too big by the same amount, and they miss each other.

Left: with a perfect phone clock, three distance circles meet at the phone. Right: with a wrong clock every circle is too big by the same amount. Shrinking them until they meet gives the clock error.

The phone looks for the one amount it can take off every circle so that they all meet. That amount is its clock error. So a flat map needs three satellites to find three unknowns: east-west, north-south and the clock. The real world has height as well, so the phone needs four. Ashby’s review states it the same way: measurements from four satellites are needed for navigation.

I checked this with a short Python program, which I ran in a Linux container. Four made-up satellites sit at the GPS orbit radius. The phone is on the surface. Its clock is 2 ms off, an arbitrary number I picked. This is the part that makes the measurements:

C = 299_792_458          # metres per second
me = (6_371_000, 0, 0)   # where the phone really is
clock_error = 2e-3       # the phone's clock is 2 ms fast

# what the phone measures to each satellite:
pseudo = [dist(sat, me) + C * clock_error for sat in sats]

The rest is a loop that guesses a position, checks the guess against the four measurements and corrects it a few times. I ran it twice on the same four readings. Once it solved only for position and pretended the clock was perfect. Once it solved for position and clock.

ignore the clock: off by 856 km
solve clock too : off by 0.0000 m, clock found = 2.000000 ms

The whole script, which also does the relativity and signal-power arithmetic in this post, is gps-fix.py. It uses only the Python standard library, so you can rerun it.

Ignoring the clock put the phone 856 km away. Solving for it found the position exactly and also recovered the 2 ms. A side effect: the phone gets very good time from GPS, not only a position.

The clocks on the satellites also need Einstein

The satellites are in orbit, so their clocks tick at a different rate from ones on the ground. Two things pull in opposite directions:

  • Gravity. The pull is weaker 20,000 km up. A clock in weaker gravity runs faster. This effect is about +45.7 microseconds per day.
  • Speed. The satellites move at about 3.9 km per second. A moving clock runs slower. This effect is about -7.2 microseconds per day.

The two do not cancel. The net is that a satellite clock runs fast by about 38 microseconds per day. ESA’s Navipedia gives the same figure. I recomputed the split with the textbook formulas in the same container and got +45.7, -7.2 and a net of about 38.5 microseconds per day, which agrees with it. The split is my arithmetic. Neither Ashby nor Navipedia states it.

At 300 km per millisecond, 38 microseconds is 11.4 km. If nobody fixed it, the position error would grow by that much every day.

Line chart: without the relativity correction a GPS satellite clock gains about 38 microseconds per day, which is 11.4 km of range error after 1 day, 34 km after 3 days and 80 km after 7 days.

The fix is made on the ground before launch. Navipedia says the clock’s nominal frequency of 10.23 MHz is lowered to 10.22999999543 MHz. Seen from the ground, the satellite then ticks at the right rate. Ashby’s abstract says that without carefully accounting for relativistic effects, the system would not work.

A smaller leftover effect comes from orbits that are not perfect circles. The receiver’s maths corrects that one. Navipedia says ignoring it gives range errors of up to 13 m.

Why GPS is weak indoors

Three separate problems.

The signal is tiny. The GPS standard says the satellites transmit with enough power for a minimum received power of -158.5 dBW on L1, the main civil signal. A dBW is a unit on a scale where every -10 means ten times less power than before, measured against one watt. As a number, -158.5 dBW is about 1.4 x 10^-16 watts, or 0.14 femtowatts. (A femtowatt is a millionth of a billionth of a watt. This conversion is my arithmetic.) Roofs and walls take more away. I did not find a published figure for how much, because it depends on the building.

A building blocks the view. The phone has to hear four satellites at once. GPS.gov says accuracy worsens near buildings, bridges and trees. Apple says “GPS accuracy depends on the number of visible GPS satellites”.

The standard’s own accuracy figures assume a clear view. The 2020 GPS standard promises a horizontal error of 8 m or less, 95% of the time, averaged over the globe. Its list of assumptions says “no local obscura are considered”. Obscura means things in the way. So the number says nothing about a street full of towers or a basement.

Echoes in the city

Between tall buildings there is a fourth problem, and it is sneakier than silence. A signal can reflect off a wall and reach the phone late. An echo like this is called multipath.

A street between tall buildings. The direct signal is blocked and a reflected copy takes a longer path, so the phone thinks the satellite is farther away and the blue dot can land on the wrong side of the street.

The Android developers’ blog explains why this hurts. The GPS chip assumes the signal came in a straight line. A bounced copy took a longer way, so the chip thinks the satellite is farther off than it is, and the position slides. Google describes the result as a “wrong-side-of-the-street position error”. In dense streets, they write, most or all signals reach you after a reflection.

Two things help:

  • 3D building maps. In December 2020 Google described a module in Google Play services that downloads 3D models of the buildings around you. It works out which buildings are bouncing the signals, and it passes corrected positions to the Fused Location Provider (more on that below). Version 2 shipped on Pixel 5 and Pixel 4a (5G). Google said other phones on Android 8 or later get version 1.
  • A second frequency. A study in the journal NAVIGATION (2021) found that the newer L5 signal “shows a much better resistibility to multipath” than the older L1 signal. GPS.gov’s accuracy page says “most of today’s civilian devices use only one GPS frequency”, so this help is not everywhere.

The cold start, and the “A” in A-GPS

A phone that has not used GPS for hours has a different problem. To use a satellite it has to know where that satellite is. The satellite sends that orbit data itself, but slowly: the GPS standard gives the data rate as 50 bits per second, and the orbit data sits in a 30 second frame that repeats. So a phone that starts from nothing has to listen for tens of seconds before it can use even one satellite.

The 3GPP location spec (TS 36.305, clause 8.1.1) says assistance data reduces the start-up and acquisition times. It gives no figure. Without help, a cold start is typically minutes rather than seconds.

Assisted GPS (A-GPS) skips most of that wait. The cell network sends the phone the satellite orbit data, the time and a rough position over the data connection, which is far faster than 50 bits per second. An explainer site (3gpp-explorer.com) lists these as the assistance data: ephemeris (orbit details), almanac (a coarser orbit list), time and approximate location. The phone still measures the satellites itself. The network only tells it where to listen.

Wi-Fi: a database of routers

Satellites are no use in a basement. Wi-Fi routers are, because they are everywhere indoors. Nobody told your phone where your neighbour’s router is. Other phones did.

Here is how the table gets filled. Phones hear the routers around them and report them together with their own position. Apple says that when Location Services is on, “your device will periodically send the geo-tagged locations of nearby Wi-Fi hotspots and cell towers to Apple”. NIST says both Apple and Google use anonymous crowdsourced data. After enough reports, the database knows roughly where each router sits.

Then the lookup works backwards. Your phone lists the routers it can hear, with their IDs and signal strength, and asks the server where that set is. (What those signal numbers in dBm mean is in why Wi-Fi is slow in one room.)

Wi-Fi positioning: the phone reports nearby access point IDs and signal strengths, and a server looks them up and returns a point with an accuracy radius. At least two access points are needed.

Mozilla ran an open-source location service, Ichnaea, until it was retired in 2024. Its API docs are still online and show the shape of such services well. The request:

{
  "wifiAccessPoints": [
    { "macAddress": "01:23:45:67:89:ab", "signalStrength": -51 },
    { "macAddress": "01:23:45:67:89:cd" }
  ]
}

A macAddress is the router’s hardware ID. The reply is a point and a radius in metres:

{ "location": { "lat": -22.7539192, "lng": -43.4371081 }, "accuracy": 100.0 }

Those are the example values from the docs. Four details from the same page are worth knowing:

  • A Wi-Fi lookup needs at least two networks. The docs call the two-network minimum “a mandatory privacy restriction”. A lookup with one router would point at a single home.
  • Only the ID is required. In the example above, the second router has no signal strength.
  • The accuracy is a 95% circle: “The user’s true position should be inside the circle with a 95th percentile confidence value.”
  • If nothing else works, the service falls back to the sender’s IP address, and the docs’ example for that case reports an accuracy of 600,000 m.

A router that moves house keeps its old record until phones report the new place. I did not find a published rate for how often this happens, so I will only say it follows from how the table is built.

Cell towers

Your phone always knows which tower it is talking to, even where there is no Wi-Fi and no sky. The tower is identified by a handful of numbers (Ichnaea needs five of them for a lookup: radio type, country code, network code, area code and cell ID). The database says where that tower is. The answer is a wide circle around it. It is the safety net: poor, but nearly always there.

Fusing it all into one dot

The operating system takes every guess and mixes them. Android’s Fused Location Provider uses “signals provided by multiple sensors in the device to determine device location” and manages “the underlying location technologies, such as GPS and Wi-Fi”. An app tells it how much accuracy to pay for: the most accurate data available, or the best it can do with no extra power. Apple’s Core Location does the same job.

How they mix is not public. NIST, who tested both, wrote that Google and Apple “do not reveal how exactly” the two work. It also says both use crowdsourced cell, satellite and Wi-Fi signals plus air pressure, and that Apple’s also uses the compass and Bluetooth.

Overlapping circles on a map: a huge cell tower circle, a large weak indoor GPS circle and a medium Wi-Fi circle. The small blue fused answer sits where they overlap. Illustration, not measured.

What the pale circle means

The pale circle that apps draw comes from a radius the phone reports with every fix. It is not decoration. Android’s documentation says getAccuracy() gives “the estimated horizontal accuracy radius in meters of this location at the 68th percentile confidence level”. In words: there is a 68% chance the true spot is inside the circle. About one time in three you are outside it.

That 68% is not the same as the other numbers you read:

FigureWhat it isConfidence
4.9 mGPS.gov: smartphones are “typically accurate to within a 4.9 m (16 ft.) radius under open sky”“typically”
8 mThe GPS standard, horizontal, global average, nobody in the way95%
16 to 33 mNIST, average miss indoors, four buildings, two phones (next section)the mean
33 to 109 mNIST, indoors, same tests95%
50 mFCC rule for emergency calls, for 80% of calls (quoted in the NIST paper)80%
Android’s circleWhatever the phone reports at the time68%
Apple’s circlehorizontalAccuracy, a radius of uncertaintyApple does not state a confidence level
Ichnaea’s circleWhatever the lookup reports95%

When one page says “accurate to 5 m” and another says “within 30 m”, check the percentage before deciding which one is lying. Often neither is.

Why the blue dot drifts indoors

NIST, the US standards lab, measured this. A tester walked two phones through five of its buildings, over almost 1,300 professionally surveyed test points, so the true position was known. They carried a Google Pixel XL (Android 9) and an iPhone 8 (iOS 11.4.1). Before most walks they stood outside for 2 to 3 minutes to be sure of a good GPS fix. The paper was published in 2019. The phones are old now, so read it as a picture of how the method behaves, not a ranking of today’s models.

Bar chart of NIST indoor error in five buildings for a Pixel XL and an iPhone 8. Mean error was 15.5 to 33.2 m in four buildings. In the underground building with 4 routers neither phone got a usable fix.

What the chart shows:

  • The average miss was 16 to 33 m, and the bad end was much worse. In Building 2, Apple’s 95% line was 109 m. The standard’s 8 m is for a clear sky.
  • Two kinds of failure. The first is wobble: the same spot gave different answers on different visits. NIST says it saw “significant variation” in estimates at the same point for both phones. The second is a frozen dot. In Building 1, which is underground, there was no cell signal and no satellite signal anywhere, and no Wi-Fi in roughly 85% of the floor area (it had 4 routers). The iPhone kept sending updates, but all of them repeated the last estimate from outside. The Android phone gave no updates inside, except a few in a small area. NIST says the same can happen in a multi-level underground car park without Wi-Fi.
  • More routers did not give a smaller miss. Building 5 had 131 and averaged 19 and 31 m. Building 4 had 8 and averaged 17 and 17 m. The buildings, the floors and the paths all differ, so this is not a clean test. It does show that the number of routers is not the whole story.
  • Wi-Fi is the reason indoor fixes work at all. The paper says both phones met the FCC’s 50 m rule for emergency calls, with the caveat that “the building has to have Wi-Fi for these gains to materialize”.

Now the full list of reasons the dot drifts. Each one is a step above:

  1. GPS is weak or full of echoes, so its circle is wide.
  2. The fallbacks (Wi-Fi, cell) have wider circles than clear-sky GPS.
  3. The mix is a judgement. When the sources disagree, the blend moves.
  4. When no source updates, the phone shows the last fix.
  5. Floors are a problem of their own. NIST reports height errors separately, and for Android in Building 5 an elevation was missing at almost 4 in 10 test points.

Questions people ask

Does GPS work without an internet connection? Yes. The satellites only broadcast, and the phone only listens, so the position needs no data connection. What the connection adds is speed (A-GPS) and the Wi-Fi and cell lookups. Without it, a cold start is typically minutes rather than seconds, and the phone cannot download map tiles.

Does GPS track me? The satellites only broadcast, so they do not know you exist. GPS.gov describes the user part of the system as receiver equipment that “receives the signals from the GPS satellites”. Tracking comes from what an app does with the position afterwards, and from the Wi-Fi and cell lookups, which do involve a server. Apple says that with Location Services on, your device periodically sends the geo-tagged locations of nearby Wi-Fi hotspots and cell towers to Apple.

Why does my location jump around indoors? The phone loses the satellites and falls back on Wi-Fi and cell towers, which give wide circles. As sources come and go, the blend moves. In the NIST tests the answers for one spot varied a lot from visit to visit.

How accurate is phone GPS? GPS.gov says a smartphone is typically accurate to within 4.9 m under open sky, and worse near buildings, bridges and trees. The GPS standard commits to 8 m or less, 95% of the time, on average over the globe, for a receiver with a clear view.

Why does GPS need relativity? The satellite clocks run about 38 microseconds a day fast compared with the ground, because of weaker gravity and high speed. At the speed of light, that is about 11 km of error per day. The clocks are set slightly slow before launch to cancel it.

Can a phone find me with GPS off? Often yes, if the phone’s location switch is on. Apple says that when satellites are blocked, the device uses Wi-Fi or cellular networks. The result is rougher.

Cheat sheet

Cheat sheet for how your phone knows where you are: time is distance (1 microsecond is 300 m), four satellites give x, y, z and the clock error, and indoors the NIST average miss was 16 to 33 m.

Further reading

Written by Rafi Loom

Backend engineer who builds high-volume systems that move money. More about Rafi