How Accurate Is IP Geolocation?
What an IP location can tell you, where it falls short, and how to test it on your own traffic.
IP geolocation estimates where an internet connection is. It doesn't track a person or a device. Country is the most reliable level. Below that, expect some gaps, and let people correct the result. To see how accurate it is for you, test it on your own traffic.
An IP address belongs to a network.
A lookup starts from an IP address, which a network uses to send traffic to a connection. It isn't a GPS reading: the place in the reply is the one linked to that address, and the person may be somewhere else.
Read the coordinates together with the accuracy radius.
IPWho returns geoLocation.accuracy_radius with the latitude and longitude. It's a distance in kilometres: the location is likely to be within that distance of the point, so a smaller number means a tighter estimate. Any of the three fields can be null.
Here is part of what the API returned for two addresses:
| Field | 91.0.0.1 | 8.8.8.8 |
|---|---|---|
country | Germany | United States |
region | North Rhine-Westphalia | null |
city | Düsseldorf | null |
latitude, longitude | 51.2294, 6.7855 | 37.751, -97.822 |
accuracy_radius | 5 | 1000 |
A map pin at the second pair of coordinates would look exact. The same reply names no city or region and gives a radius of 1,000 km. If you draw a map, show an area, or show only the country name.
8.8.8.8 is Google's public DNS resolver, which is reached at many places. So even the country shown for it may not be where a request to it is answered.
A city can be empty or wrong for ordinary reasons.
- Anycast. One address can be made available in many separate places, with traffic sent to one of them. Large public services use this, so a single location can't describe the address.
- Shared addresses. With carrier-grade NAT, several subscribers of a provider share one IPv4 address. They needn't be in the same place, so one answer can't be right for all of them if they are far apart. Take extra care with city results for mobile visitors.
- VPNs and proxies. Your server sees the address of the VPN or proxy, so the location describes that.
- Privacy relays. With iCloud Private Relay, websites visited in Safari see a temporary address from a relay, not the user's own address.
- Changes over time. Networks can move address blocks to other places, and any location data can lag behind.
Use only the level of detail that the reply supports.
This function shows a city only when there is one and its radius is within a limit you choose. Otherwise it falls back to the country, then to “unknown”. The limit depends on your product, and we aren't recommending a number.
// The most detailed place name you can reasonably show for one lookup.
// maxCityRadiusKm is YOUR choice. Set it for your product and test it on your own traffic.
export function bestPlace(geo, maxCityRadiusKm) {
const radius = geo?.accuracy_radius;
if (geo?.city && typeof radius === 'number' && radius <= maxCityRadiusKm) {
return { level: 'city', name: geo.city };
}
if (geo?.country) return { level: 'country', name: geo.country };
return { level: 'unknown', name: null };
}
With an example limit of 50, the two replies above give the city for 91.0.0.1 and the country for 8.8.8.8. Call the API from your server, and pass the function the reply's data.geoLocation object.
- Use the result as a default, and let people change their country, currency or city.
- Don't use it as someone's address, or to identify a person.
- If a decision matters, such as refusing an order or an account, don't rest it on an IP location alone.
Measure accuracy on your own traffic.
One published percentage can't tell you how a service will do on your mix of countries and networks. A small test can:
- Take a recent sample of IP addresses for which you also have a country or city you trust, such as one the person told you. Use only data your privacy notice allows you to use this way.
- Look up each address. The free plan gives 2,000 lookups a day, with every field.
- For both country and city, count three things: matched, different and empty.
- Split the results by country and by
connection.connection_type, because an average can hide a weak group. Treat an empty connection type as its own group. - Write down the sample size and the date next to every rate.
A mismatch isn't always a lookup error. People travel, use VPNs and give a home address while they're somewhere else. Check a few mismatches by hand before you judge.
Common questions
Can IP geolocation find a street address?
No. An IP lookup is an estimate about an internet connection. Even when it returns a city, postal code and coordinates, it doesn't tell you the address where a person is.
Why does a lookup return a country but no city?
City, region and postal code can be empty, and sometimes the country is too. Some addresses can't be tied to one place, such as an anycast address that is served from many locations. Write your code so an empty city is normal.
What location do you get for someone using a VPN?
The lookup describes the address your server sees. With a VPN, that is usually the VPN service's exit server, not the place where the person is.
Check your own addresses
Try one address in the IP geolocation lookup tool, or test a sample with a free key: 2,000 lookups a day, no card. See the location fields for the full list.