DEV Community

Vix
Vix

Posted on

Why "your IP says you're in the wrong place" isn't a bug

Why "your IP says you're in the wrong place" isn't a bug

If you've ever seen a website confidently tell a user they're in a country they've never visited, you've witnessed IP geolocation doing exactly what it's designed to do — making a statistical guess, not reporting a fact. This is one of the most misunderstood pieces of everyday internet infrastructure, and misunderstanding it leads to real product decisions that hurt real users. This article explains why "wrong" geolocation is usually not a bug, and what that means for how you build with it.


The core misconception

Most people (and a surprising number of developers) assume an IP address is tied to a location the way a phone number is tied to an area code — fixed, verifiable, looked up rather than inferred. It isn't.

An IP address is assigned to an organization — an ISP, a company, a hosting provider. Geolocation databases infer a probable physical location for that organization's infrastructure using registry records, routing data, and probabilistic modeling. There is no authoritative global database that maps "this exact IP → this exact building." There never has been, and there isn't likely to be one, because IP allocation was never designed with precise physical location in mind.

This means every "your location" you've ever seen online was always a best guess dressed up as a fact.


Why organizations route traffic through single points

The deeper reason geolocation looks "wrong" so often: modern internet infrastructure is built around centralizing traffic, not distributing it.

Mobile carriers route thousands of users through shared carrier-grade NAT gateways — a rural user's traffic might exit through a datacenter in the nearest major city, sometimes hundreds of kilometers away.

Enterprises and institutions frequently centralize all internet-bound traffic through one gateway, one datacenter, one region — regardless of where individual employees or devices physically sit. A user in one city might show up as being wherever their organization's network egress point happens to be.

Cloud providers don't represent users at all — traffic from AWS, Google Cloud, or Azure represents whatever server is making the request, which could be anywhere the provider has a datacenter.

VPNs are explicitly designed to make this happen on purpose.

None of these are edge cases. Combined, they represent a very large share of real-world internet traffic. "Wrong" geolocation isn't a rare failure — it's the expected outcome for a substantial fraction of any real user base.


Verifying this yourself

You can see exactly what a geolocation service infers for any IP, including the organizational data that explains why it might not match a physical user:

curl "https://ippubblico.org/?api=1"
Enter fullscreen mode Exit fullscreen mode
{
  "status": "ok",
  "ip": "203.0.113.42",
  "isp": "Some Corporate Network",
  "asn": "AS64500",
  "geo": {
    "city": "Frankfurt",
    "country": "Germany",
    "country_code": "DE"
  }
}
Enter fullscreen mode Exit fullscreen mode

The isp and asn fields are often more informative than the city/country fields — they tell you whose infrastructure you're actually looking at, which is frequently the real answer to "why does this look wrong."


What "accuracy" actually means in this context

Geolocation accuracy is usually reported as a percentage — "99% accurate at the country level," for example. This number describes how often the inferred location matches a ground truth dataset, typically built from ISP registration records. It does not mean 99% of real users will see correct results, because ground truth datasets skew toward stable residential and fixed-line connections — exactly the segment least likely to have the failure modes described above.

Mobile users, corporate users, VPN users, and cloud traffic are systematically underrepresented in the datasets used to measure accuracy, and systematically overrepresented in real-world complaints about geolocation being wrong. The reported accuracy number and the accuracy your users experience can be very different things, and the direction of that gap is predictable.


The practical implication for developers

This isn't an argument against using IP geolocation — it's an argument for using it the way it actually works, rather than the way it's often marketed.

import requests

def get_location_context(ip: str = None) -> dict:
    """
    Returns geolocation as a *hint*, not a fact.
    Callers should treat this as a default to offer, never a
    determination to enforce.
    """
    url = 'https://ippubblico.org/?api=1'
    if ip:
        url += f'&ip={ip}'

    data = requests.get(url, timeout=5).json()

    return {
        'suggested_country': data.get('geo', {}).get('country_code'),
        'confidence_flags': {
            'is_datacenter': _looks_like_datacenter(data.get('isp', '')),
            'is_mobile_carrier': _looks_like_mobile(data.get('isp', '')),
        }
    }

def _looks_like_datacenter(isp: str) -> bool:
    keywords = ['amazon', 'google', 'microsoft azure', 'digitalocean',
                'ovh', 'hetzner', 'linode', 'vultr']
    return any(k in isp.lower() for k in keywords)

def _looks_like_mobile(isp: str) -> bool:
    keywords = ['mobile', 'wireless', 'cellular', '4g', '5g', 'lte']
    return any(k in isp.lower() for k in keywords)
Enter fullscreen mode Exit fullscreen mode

The confidence_flags pattern matters more than most tutorials suggest — knowing when not to trust a result is often more useful than the result itself.


A concrete example of getting this wrong

A common real-world failure: an e-commerce site uses IP geolocation to lock in a currency and won't let users change it, "for their protection." A business traveler, a student abroad, or simply someone on a VPN sees prices in the wrong currency and cannot check out. This isn't a rare bug report — it's one of the most common geolocation-related complaints across e-commerce support forums, precisely because the assumption "IP accurately reflects the shopper's location" fails constantly for exactly the population most likely to be shopping while traveling.

The fix is almost always the same: use geolocation to pre-select a sensible default, and always, always let the user override it. This single design choice eliminates the vast majority of geolocation-related user complaints without sacrificing the convenience geolocation provides for the (large) majority of users for whom it's correct.


When "wrong" geolocation is actually a useful signal

Sometimes the mismatch itself is the interesting data point, not an error to hide.

def flag_suspicious_mismatch(claimed_country: str, ip: str) -> bool:
    """
    Not a security decision by itself — a signal to combine
    with other factors (never block solely on this).
    """
    data = requests.get(f'https://ippubblico.org/?api=1&ip={ip}').json()
    detected = data.get('geo', {}).get('country_code')

    if detected and claimed_country and detected != claimed_country:
        # Could mean: VPN, traveling, proxy, or genuinely fraudulent —
        # geolocation alone can't tell you which
        return True
    return False
Enter fullscreen mode Exit fullscreen mode

A mismatch between a user's stated location (billing address, account settings) and detected IP location is a legitimate fraud-detection signal — one input among many, never a standalone determination. Treating the mismatch itself as useful information, rather than as a failure of the geolocation service, reframes the entire problem correctly.


The honest summary

IP geolocation is a probabilistic inference over organizational network assignment data, not a location lookup. It's "wrong" — meaning it doesn't match the individual user's physical location — for a substantial, structurally predictable share of real traffic: mobile users, corporate networks, VPNs, and cloud/datacenter sources. This isn't a quality problem with any particular provider's database; it's inherent to what the technology is doing.

The fix isn't a more accurate database. It's building software that treats geolocation as a default suggestion rather than a fact to enforce, checks ASN/ISP data to flag likely-unreliable cases, and always gives users a way to correct it.

Full documentation: ippubblico.org/docs.html
Try it yourself: ippubblico.org


What's the most memorably wrong geolocation result you've seen in production? Always curious to hear the specific war stories.

Top comments (0)