IP 2 Country API

⭐ Beginner's Pick Geocoding / No Auth Required Beginner HTTPS
Free to Use Varies (check documentation)

Overview

IP 2 Country is a free, no-auth API that maps any IPv4 address to its corresponding country. It is useful for basic geolocation features like redirecting users or showing region-specific content. Just pass an IP address as a query parameter to get the country code back.

💡

Beginner Tip

This API only returns country-level data, not city or region. For more detailed IP geolocation, consider ipinfo.io or ip-api.com. It works well as a lightweight first step for country detection in backend scripts.

Available Data

country name and code
population
capital city
region and subregion
flag image URL
IP address information

Example Response

JSON Response
{
  "name": "Japan",
  "capital": "Tokyo",
  "population": 125800000,
  "region": "Asia",
  "languages": [
    "Japanese"
  ],
  "flag": "https://flagcdn.com/jp.svg",
  "currencies": [
    {
      "code": "JPY",
      "name": "Japanese yen"
    }
  ]
}

Field Reference

countryCode ISO 3166-1 alpha-2 two-letter country code, e.g. US, DE, JP.
countryCode3 ISO 3166-1 alpha-3 three-letter country code, e.g. USA, DEU, JPN.
countryName Full English name of the country the IP belongs to.
countryEmoji Flag emoji character for the country.

Implementation Example

const url = "https://ip2country.info/";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

Empty or null country response The IP address is a private, reserved, or loopback address like 127.0.0.1.
Only pass public IPv4 addresses. Test with a real external IP like 8.8.8.8 first.
400 Bad Request The IP address format is invalid.
Ensure the IP is a valid IPv4 format (e.g. 203.0.113.45) without extra characters or spaces.
Unknown country code Some IPs are not mapped in the database.
Handle missing or null results gracefully in your code with a fallback value.

Matrix Score Breakdown

🌐 Reachability 30/30
⚡ Speed 20/20
🔒 Security 15/15
🛠 Developer XP 15/20
✓ Reliability 7/15
Response Time 35ms

Fully tested on Apr 5, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS UNKNOWN
Category Geocoding
Difficulty Beginner
Verified: 2026-04-04

Similar APIs

View All →