Published on Nov 19, 2026Ghadeer Al-MashhadiRead time: 12m39 viewer
IP to Country Lookup: How It Works, How Accurate It Is, and How to Use It

IP to Country Lookup: How It Works, How Accurate It Is, and How to Use It

Introduction

Every request that reaches your site or app carries an IP address. The address is just a number, but it comes attached to a country. When you can see that a signup came from one country while the card was issued in another, or that a returning customer suddenly logs in from a country they have never used before, you have context you can act on.

That is what an IP to country lookup gives you: a fast answer to the question "where does this connection come from?" at the country level, in a form your rules can use.

For anyone taking payments online, that question is far from academic. Transactions that cross borders behave very differently from domestic ones, and not in a good way. The joint report from the European Banking Authority and the European Central Bank on payment fraud across the EEA puts a number on it:

"However, in all periods analysed, around 70% of card payment fraud was related to cross-border transactions in terms of both value and volume (see Charts 25b and 26b)." Source: EBA and ECB, 2025 Report on Payment Fraud

This guide explains how an IP to country lookup works, where the data comes from, how far you can trust it, and how to use it in signup, login and checkout flows. If you are newer to the topic, our introduction to IP geolocation is a good starting point.

What an IP to Country Lookup Actually Returns

An IP to country lookup takes an IPv4 or IPv6 address, such as 165.227.149.217, and returns the country that address maps to. You normally get two fields back: a human readable name such as Germany, and a two letter country code such as DE.

The lookup is the country level slice of IP geolocation. The same response usually carries a continent, and often a city, postal code, timezone and currency as well. Country is the coarsest answer, and as it turns out, the most dependable one.

It is also worth separating two questions people often blur together. Country lookup asks "where is this address?" IP reputation asks "what has this address been doing?" Both matter at checkout, and they answer different things.

Where the Country Data Comes From

IP address space is managed from the top down. IANA, the Internet Assigned Numbers Authority, delegates large blocks of addresses to five Regional Internet Registries: ARIN, RIPE NCC, APNIC, LACNIC and AFRINIC. Each registry assigns smaller ranges to networks and records the assignee, including a country, in its public registry data.

That registration layer is the backbone of every IP to country database. If a range is assigned to an internet provider in Frankfurt, that range starts life mapped to Germany.

Commercial providers refine it from there. They watch routing announcements, run latency measurements from known locations, and blend signals from their own networks of probes and users. The result is a mapping per address, or per small block, that is updated continuously. Greip's IP Location Intelligence service returns the country along with city level fields, timezone, currency and network context.

How Accurate Is a Country Level Answer?

Country is the strongest signal in the whole IP geolocation stack. Registries record it directly, ranges rarely move between countries, and providers can verify it with many independent signals. The deeper you go below country level, into city, postal code or street, the thinner the evidence gets, so treat those fields as hints rather than facts.

A few honest caveats:

  • Carrier grade NAT. Mobile networks place large populations behind shared gateways. The lookup sees the gateway, not the person, so a user near a border can show up in the neighbouring country.
  • Corporate registrations. A company may register its ranges at headquarters while traffic exits somewhere else entirely.
  • Satellite providers. Satellite internet often maps to the operator's home country rather than the dish's actual location.
  • Bogon addresses. Private and reserved ranges such as 10.0.0.0/8 have no country at all. A good lookup response flags them as bogons instead of guessing.

Why VPNs and Proxies Make the Country Answer Unreliable

When someone connects through a VPN or proxy, the country you see is the country of the exit server, not the person. A fraudster in one country can appear to be a local shopper in yours with a cheap VPN subscription.

This is why the country answer should never travel alone. Greip's lookup can return a security module alongside the geolocation fields, with flags such as vpn_or_proxy, vpn_or_proxy_type, tor, bot, relay and hosting. A country answer on a clean residential line means something quite different from the same answer on a flagged hosting range.

Treat the country of a VPN or proxy connection as an unverified claim. Put the country and the security flags into the same rule, so the decision reflects both signals at once.

Use Case: Catching Billing Country Mismatch at Checkout

The classic application for the country signal is the three way country check at payment time. You know the billing country the customer typed in. You can know the issuing country of the card, because a BIN Lookup reads the first six to eight digits and returns the issuing bank and country. And you can know the IP country.

When the three agree, that is quiet, boring confidence. When the card was issued in one country, the billing address is in a second, and the connection comes from a third behind a proxy, you have a decision to make before the money moves.

For payouts the same idea works with bank details. An IBAN encodes its country in the first characters, so IBAN validation gives you another country to compare against the IP.

Our integration guide walks through the whole verify card BIN and IBAN country against the IP flow, including how to structure an allow, challenge or block policy around the comparison.

Use Case: Pricing Cross-Border Risk at Signup

The same EBA and ECB report found that fraud rates for card payments were about seventeen times higher when the counterpart was outside the EEA than for domestic transactions. Cross-border activity is where the risk concentrates, so it deserves its own signals rather than one blanket rule.

That starts at account creation. A signup whose IP country differs from the phone country code, or from the country in their email profile, is not automatically bad, but it is a reason to score before you send a welcome discount code. Velocity makes it sharper: one device or email registering accounts against several countries in a day is a pattern, not a coincidence.

Use Case: Tax, Licensing and Compliance Signals

Country answers also feed the softer parts of running an online business:

  • Localized pricing. The lookup response includes a currency object, so you can show prices in the visitor's currency and set expectations before checkout.
  • Regional rules. An is_eu flag on the response helps route privacy and consent flows for European visitors.
  • Licensing. Content that may only be shown in certain countries starts with knowing the visitor's country.
  • Reference data. For anything driven by country, Greip's Country Intelligence service returns reference data such as currency, languages, timezones and borders.

An IP country answer is a signal, not a tax determination. VAT and GST place of supply rules rely on billing address and other evidence. Use the IP country for risk scoring and UX choices, and confirm tax obligations with qualified advisers.

How to Run the Lookup with Greip

The lookup is one server side call. Greip's v2 API exposes GET /lookup/ip/{ip} for any address you already have, documented in full in the IP Lookup endpoint reference. Your key goes in the Authorization header, never in the query string.

GET https://v2.greipapi.com/lookup/ip/165.227.149.217?params=security,currency,timezone
Authorization: Bearer ***

The params command adds response modules: security, currency, timezone, location and device on top of the basic ip and geo fields. There is also a mode parameter, so you can run calls with mode=test while integrating.

This trimmed example comes from the documentation:

{
  "success": true,
  "data": {
    "ip": {
      "address": "165.227.149.217",
      "version": 4,
      "bogon": false
    },
    "geo": {
      "continent": "Europe",
      "country": "Germany",
      "country_code": "DE",
      "region": "Hessen",
      "city": "Frankfurt am Main"
    },
    "asn": {
      "number": "AS14061",
      "name": "DIGITALOCEAN-ASN",
      "type": "hosting"
    },
    "security": {
      "vpn_or_proxy": true,
      "vpn_or_proxy_type": "VPN",
      "tor": false,
      "bot": false
    }
  },
  "execution_ms": 42
}

Read the country from data.geo.country and the code from data.geo.country_code. Notice what the sample shows: a hosting range, flagged as a VPN, carrying a German country answer. That is exactly the kind of nuance a bare country code would hide.

To get the visitor's IP on the server, read it from your framework's request object. If you sit behind a load balancer, trust X-Forwarded-For only from your own proxy, never a value a client can set directly.

The endpoint is available on Standard plans and above, and every new account starts with a 3-day trial that includes 1,000 requests, which is plenty to test the flow.

Free Tools, Offline Databases and Real-Time APIs

There are three practical ways to get a country from an IP address:

  • Free online tools. For one-off manual checks, the Greip IP lookup tool shows the country, city, timezone, ASN and network context for your own address or any IPv4 or IPv6 address you paste in.
  • Offline databases. Vendors such as MaxMind and IP2Location publish downloadable country databases you self host. Lookups are local and fast, with no per-request cost, but you own the update discipline: a database you forget to refresh quietly goes stale, and the free tiers come with their own license terms. You also get no security flags, so VPN and bot detection has to come from somewhere else.
  • Real-time APIs. A service like Greip keeps the mapping fresh, adds the security, reputation and network modules on top of the country answer, and needs no infrastructure from you. The Standard plan includes 170,000 requests per month.

For fraud and trust decisions, the real-time API is the one that holds up, because the country answer on its own is only half the story.

Turning the Country Answer into Fraud Rules

A simple starting policy has three tiers:

  • Allow. Countries are consistent across IP, BIN or IBAN and billing, no security flags, normal velocity. Standard flow, no friction.
  • Challenge. A country mismatch, or a VPN flag on a payment context. Step up with 3D Secure or manual review before the transaction proceeds.
  • Block. A sanctioned or unsupported country, or a hosting range on a payment page with no legitimate explanation. Stop it early.

Two operational habits make the signal better over time. Cache lookups you trust for a short window if volume is high, and store the full response with each order or signup. When a chargeback or dispute arrives months later, the country context you recorded at the time is worth a great deal.

Start with fixed thresholds and adjust them with your own chargeback and false positive data. The country signal is cheap to log and gets more valuable the longer you keep it.

Common Mistakes to Avoid

  1. Blocking entire countries. Blunt rules also block genuine travellers, expats and remote teams, and they hand your blocked customers to competitors. For a fuller discussion of when to block, challenge or allow by country, see our guide to geo-blocking for online businesses.
  2. Trusting city or postal fields. The country answer is dependable; the street level answer is a guess dressed up as data. Build rules on country, use the deeper fields only for UX.
  3. Calling the IP country the billing country. They answer different questions. One is where the connection came from, the other is where the customer says they live. Compare them instead of merging them.
  4. Forgetting IPv6. Adoption keeps growing, and a lookup that chokes on IPv6 addresses will misclassify a growing share of traffic for no reason.
  5. Doing the lookup client side. A lookup run in the browser can be tampered with before you ever see it. Run it server side, from code you control.

Frequently Asked Questions

What is an IP to country lookup?

An IP to country lookup maps an IP address to the country the connection comes from. It returns a country name and a two letter country code, such as DE for Germany, usually alongside continent, timezone and currency fields.

How accurate is an IP to country lookup?

Country is the most reliable level of IP geolocation because it comes straight from registry data. Accuracy drops for city and postal code fields. VPNs, proxies and carrier grade NAT can still return a country that does not match the person behind the address, so pair the country answer with security flags.

Is there a free IP to country API?

Greip includes the IP to country lookup on every plan, and new accounts get a 3-day trial with 1,000 requests. For manual one-off checks, the free IP lookup tool on the Greip tools page shows the country for any address without an API key.

How do I get the country from an IP address in my code?

Call the Greip IP Lookup endpoint server side with GET /lookup/ip/{ip}, passing your API key in the Authorization header. The response contains the country name in data.geo.country and the two letter code in data.geo.country_code.

Can a VPN hide the real country of an IP address?

Yes. A VPN or proxy answers with the country of its exit server, not the person using it. The Greip lookup flags these connections with vpn_or_proxy and related fields in the security module, so you can treat the country as unverified and decide what extra proof to request.

Should I use IP country for tax decisions?

No. An IP country is one signal among several. VAT and GST place of supply rules generally rely on billing address and other evidence, so use the IP country for risk scoring and UX choices, and confirm tax obligations with qualified advisers.

Conclusion

The country behind an IP address is cheap to get, quick to act on, and wrong just often enough to keep you honest. It earns its place in a fraud stack when it travels with the security flags, when it is compared against the BIN or IBAN country instead of standing alone, and when it is recorded with the order for the day you need the evidence back.

Start with a small allow, challenge and block policy around the country signal, run the lookup server side on every signup and checkout, and let your own chargeback data tell you where to tighten. The signal is small, but it is one of the few you can collect on every single request without asking the customer for anything.

Get started

Start protecting your business today

Our service is trusted by thousands of businesses worldwide.

  • 1,000 requests during trial
  • Cancel anytime

Related Articles