ISO 3166 country codes are standardized codes used to represent countries and territories worldwide. This comprehensive guide covers alpha-2, alpha-3, and numeric codes essential for international web development, APIs, and e-commerce.
Table of Contents
- What Are ISO 3166 Country Codes?
- Types of Country Codes
- Most Common Country Codes
- Using Country Codes in Development
- Country Codes for APIs
- Complete Country List
- Best Practices
What Are ISO 3166 Country Codes?
ISO 3166 is an international standard for country codes maintained by the International Organization for Standardization (ISO). These codes are used worldwide for:
- E-commerce: Shipping addresses, tax calculations
- APIs: Location data, payment processing
- Forms: Country selection dropdowns
- Databases: Storing nationality, location
- Analytics: Geographic reporting
- Localization: Language and region settings
Standard Authority: ISO 3166 codes are maintained by ISO and updated regularly. Always check for the latest additions or changes, especially for newly recognized territories.
Types of Country Codes
ISO 3166 provides three different code formats for each country:
Alpha-2 Codes (2-Letter)
Format: Two uppercase letters
Example: US, GB, CA
Most commonly used for:
- Top-level domains (
.us,.uk,.ca) - Language tags (
en-US,en-GB) - Currency codes prefix
- Most APIs and databases
// Most common usage
const country = 'US'; // United States
const locale = 'en-US'; // English (United States)
const domain = 'example.us';
Alpha-3 Codes (3-Letter)
Format: Three uppercase letters
Example: USA, GBR, CAN
Most commonly used for:
- Vehicle registration plates
- Currency codes (ISO 4217)
- International shipping
- Some government systems
// Alpha-3 usage
const country = 'USA'; // United States
const currencyCode = 'USD'; // Starts with country alpha-3
Numeric Codes (3-Digit)
Format: Three digits (with leading zeros)
Example: 840, 826, 124
Most commonly used for:
- Systems that don't support Latin characters
- UN statistics
- International databases
- Some payment systems
// Numeric usage
const country = '840'; // United States
const countryCode = 840; // As integer
| format | example | length | usage |
|---|---|---|---|
| Alpha-2 | US | 2 letters | Most common |
| Alpha-3 | USA | 3 letters | Currency codes |
| Numeric | 840 | 3 digits | UN systems |
Most Common Country Codes
Top 20 Countries by Population
| Country | Alpha-2 | Alpha-3 | Numeric | Population Rank |
|---|---|---|---|---|
| China | CN | CHN | 156 | 1 |
| India | IN | IND | 356 | 2 |
| United States | US | USA | 840 | 3 |
| Indonesia | ID | IDN | 360 | 4 |
| Pakistan | PK | PAK | 586 | 5 |
| Brazil | BR | BRA | 076 | 6 |
| Nigeria | NG | NGA | 566 | 7 |
| Bangladesh | BD | BGD | 050 | 8 |
| Russia | RU | RUS | 643 | 9 |
| Mexico | MX | MEX | 484 | 10 |
| Japan | JP | JPN | 392 | 11 |
| Philippines | PH | PHL | 608 | 12 |
| Egypt | EG | EGY | 818 | 13 |
| Ethiopia | ET | ETH | 231 | 14 |
| Vietnam | VN | VNM | 704 | 15 |
| Congo (DRC) | CD | COD | 180 | 16 |
| Turkey | TR | TUR | 792 | 17 |
| Iran | IR | IRN | 364 | 18 |
| Germany | DE | DEU | 276 | 19 |
| Thailand | TH | THA | 764 | 20 |
View United States (US) | View China (CN) | View India (IN)
Major English-Speaking Countries
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| United States | US | USA | 840 |
| United Kingdom | GB | GBR | 826 |
| Canada | CA | CAN | 124 |
| Australia | AU | AUS | 036 |
| New Zealand | NZ | NZL | 554 |
| Ireland | IE | IRL | 372 |
| South Africa | ZA | ZAF | 710 |
European Union Countries
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| Germany | DE | DEU | 276 |
| France | FR | FRA | 250 |
| Italy | IT | ITA | 380 |
| Spain | ES | ESP | 724 |
| Poland | PL | POL | 616 |
| Netherlands | NL | NLD | 528 |
| Belgium | BE | BEL | 056 |
| Sweden | SE | SWE | 752 |
| Austria | AT | AUT | 040 |
| Greece | GR | GRC | 300 |
UK Note: The United Kingdom uses GB (Great Britain) as its alpha-2 code, not UK. While UK is reserved, GB is the official ISO code. Some systems accept both.
Using Country Codes in Development
HTML Country Select Dropdown
<select name="country" id="country">
<option value="">Select a country...</option>
<option value="US">United States</option>
<option value="GB">United Kingdom</option>
<option value="CA">Canada</option>
<option value="AU">Australia</option>
<option value="DE">Germany</option>
<option value="FR">France</option>
<option value="JP">Japan</option>
<option value="CN">China</option>
<!-- ... more countries -->
</select>
JavaScript Country Data Structure
const countries = [
{
name: 'United States',
alpha2: 'US',
alpha3: 'USA',
numeric: '840',
currency: 'USD',
languages: ['en'],
flag: 'πΊπΈ'
},
{
name: 'United Kingdom',
alpha2: 'GB',
alpha3: 'GBR',
numeric: '826',
currency: 'GBP',
languages: ['en'],
flag: 'π¬π§'
},
{
name: 'Germany',
alpha2: 'DE',
alpha3: 'DEU',
numeric: '276',
currency: 'EUR',
languages: ['de'],
flag: 'π©πͺ'
}
// ... more countries
];
// Usage
function getCountryByCode(alpha2Code) {
return countries.find(c => c.alpha2 === alpha2Code);
}
const country = getCountryByCode('US');
console.log(country.name); // "United States"
console.log(country.currency); // "USD"
TypeScript Interface
interface Country {
name: string;
alpha2: string;
alpha3: string;
numeric: string;
currency: string;
languages: string[];
flag: string;
continent?: string;
region?: string;
}
const country: Country = {
name: 'United States',
alpha2: 'US',
alpha3: 'USA',
numeric: '840',
currency: 'USD',
languages: ['en'],
flag: 'πΊπΈ',
continent: 'North America',
region: 'Americas'
};
React Country Selector Component
import { useState } from 'react';
const countries = [
{ code: 'US', name: 'United States', flag: 'πΊπΈ' },
{ code: 'GB', name: 'United Kingdom', flag: 'π¬π§' },
{ code: 'CA', name: 'Canada', flag: 'π¨π¦' },
// ... more countries
];
function CountrySelector({ value, onChange }) {
return (
<select
value={value}
onChange={(e) => onChange(e.target.value)}
className="country-selector"
>
<option value="">Select a country...</option>
{countries.map(country => (
<option key={country.code} value={country.code}>
{country.flag} {country.name}
</option>
))}
</select>
);
}
// Usage
function ShippingForm() {
const [country, setCountry] = useState('');
return (
<div>
<label>Country:</label>
<CountrySelector value={country} onChange={setCountry} />
{country && <p>Selected: {country}</p>}
</div>
);
}
Searchable Country Dropdown
function createSearchableCountryDropdown(countries, inputId, listId) {
const input = document.getElementById(inputId);
const list = document.getElementById(listId);
input.addEventListener('input', (e) => {
const searchTerm = e.target.value.toLowerCase();
const filtered = countries.filter(country =>
country.name.toLowerCase().includes(searchTerm) ||
country.alpha2.toLowerCase().includes(searchTerm)
);
list.innerHTML = filtered
.map(country => \`
<div class="country-option" data-code="\${country.alpha2}">
<span class="flag">\${country.flag}</span>
<span class="name">\${country.name}</span>
<span class="code">\${country.alpha2}</span>
</div>
\`)
.join('');
});
list.addEventListener('click', (e) => {
const option = e.target.closest('.country-option');
if (option) {
const code = option.dataset.code;
input.value = option.querySelector('.name').textContent;
input.dataset.countryCode = code;
list.style.display = 'none';
}
});
}
Country Codes for APIs
REST API Examples
// Get user location by country code
GET /api/users?country=US
// Filter products by country
GET /api/products?shipping_country=GB
// Get country information
GET /api/countries/US
// Response
{
"alpha2": "US",
"alpha3": "USA",
"numeric": "840",
"name": "United States",
"currency": "USD",
"languages": ["en"],
"region": "Americas"
}
Payment Processing
// Stripe payment intent with country
const paymentIntent = await stripe.paymentIntents.create({
amount: 1000,
currency: 'usd',
payment_method_types: ['card'],
shipping: {
name: 'John Doe',
address: {
line1: '123 Main St',
city: 'New York',
state: 'NY',
postal_code: '10001',
country: 'US' // ISO 3166 alpha-2 code
}
}
});
// PayPal
{
"payer": {
"address": {
"country_code": "US" // ISO 3166 alpha-2 code
}
}
}
Shipping APIs
// FedEx, UPS, DHL typically use alpha-2 codes
const shipment = {
origin: {
country: 'US',
city: 'New York',
zip: '10001'
},
destination: {
country: 'GB',
city: 'London',
zip: 'SW1A 1AA'
}
};
// Calculate shipping rates
fetch('/api/shipping/rates', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(shipment)
});
Geolocation APIs
// IP Geolocation
const response = await fetch('https://ipapi.co/json/');
const data = await response.json();
console.log(data.country_code); // "US"
console.log(data.country_name); // "United States"
// Google Maps Geocoding API
{
"address_components": [
{
"long_name": "United States",
"short_name": "US", // ISO 3166-1 alpha-2
"types": ["country", "political"]
}
]
}
Complete Country List
A-D
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| Afghanistan | AF | AFG | 004 |
| Albania | AL | ALB | 008 |
| Algeria | DZ | DZA | 012 |
| Andorra | AD | AND | 020 |
| Angola | AO | AGO | 024 |
| Argentina | AR | ARG | 032 |
| Armenia | AM | ARM | 051 |
| Australia | AU | AUS | 036 |
| Austria | AT | AUT | 040 |
| Azerbaijan | AZ | AZE | 031 |
| Bahamas | BS | BHS | 044 |
| Bahrain | BH | BHR | 048 |
| Bangladesh | BD | BGD | 050 |
| Barbados | BB | BRB | 052 |
| Belarus | BY | BLR | 112 |
| Belgium | BE | BEL | 056 |
| Belize | BZ | BLZ | 084 |
| Benin | BJ | BEN | 204 |
| Bhutan | BT | BTN | 064 |
| Bolivia | BO | BOL | 068 |
| Bosnia and Herzegovina | BA | BIH | 070 |
| Botswana | BW | BWA | 072 |
| Brazil | BR | BRA | 076 |
| Brunei | BN | BRN | 096 |
| Bulgaria | BG | BGR | 100 |
| Burkina Faso | BF | BFA | 854 |
| Burundi | BI | BDI | 108 |
| Cambodia | KH | KHM | 116 |
| Cameroon | CM | CMR | 120 |
| Canada | CA | CAN | 124 |
| Cape Verde | CV | CPV | 132 |
| Central African Republic | CF | CAF | 140 |
| Chad | TD | TCD | 148 |
| Chile | CL | CHL | 152 |
| China | CN | CHN | 156 |
| Colombia | CO | COL | 170 |
| Comoros | KM | COM | 174 |
| Congo | CG | COG | 178 |
| Costa Rica | CR | CRI | 188 |
| Croatia | HR | HRV | 191 |
| Cuba | CU | CUB | 192 |
| Cyprus | CY | CYP | 196 |
| Czech Republic | CZ | CZE | 203 |
| Denmark | DK | DNK | 208 |
| Djibouti | DJ | DJI | 262 |
| Dominica | DM | DMA | 212 |
| Dominican Republic | DO | DOM | 214 |
E-I
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| Ecuador | EC | ECU | 218 |
| Egypt | EG | EGY | 818 |
| El Salvador | SV | SLV | 222 |
| Estonia | EE | EST | 233 |
| Ethiopia | ET | ETH | 231 |
| Fiji | FJ | FJI | 242 |
| Finland | FI | FIN | 246 |
| France | FR | FRA | 250 |
| Gabon | GA | GAB | 266 |
| Gambia | GM | GMB | 270 |
| Georgia | GE | GEO | 268 |
| Germany | DE | DEU | 276 |
| Ghana | GH | GHA | 288 |
| Greece | GR | GRC | 300 |
| Guatemala | GT | GTM | 320 |
| Guinea | GN | GIN | 324 |
| Haiti | HT | HTI | 332 |
| Honduras | HN | HND | 340 |
| Hungary | HU | HUN | 348 |
| Iceland | IS | ISL | 352 |
| India | IN | IND | 356 |
| Indonesia | ID | IDN | 360 |
| Iran | IR | IRN | 364 |
| Iraq | IQ | IRQ | 368 |
| Ireland | IE | IRL | 372 |
| Israel | IL | ISR | 376 |
| Italy | IT | ITA | 380 |
J-P
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| Jamaica | JM | JAM | 388 |
| Japan | JP | JPN | 392 |
| Jordan | JO | JOR | 400 |
| Kazakhstan | KZ | KAZ | 398 |
| Kenya | KE | KEN | 404 |
| Kuwait | KW | KWT | 414 |
| Kyrgyzstan | KG | KGZ | 417 |
| Laos | LA | LAO | 418 |
| Latvia | LV | LVA | 428 |
| Lebanon | LB | LBN | 422 |
| Libya | LY | LBY | 434 |
| Lithuania | LT | LTU | 440 |
| Luxembourg | LU | LUX | 442 |
| Malaysia | MY | MYS | 458 |
| Mexico | MX | MEX | 484 |
| Morocco | MA | MAR | 504 |
| Netherlands | NL | NLD | 528 |
| New Zealand | NZ | NZL | 554 |
| Nigeria | NG | NGA | 566 |
| Norway | NO | NOR | 578 |
| Pakistan | PK | PAK | 586 |
| Panama | PA | PAN | 591 |
| Peru | PE | PER | 604 |
| Philippines | PH | PHL | 608 |
| Poland | PL | POL | 616 |
| Portugal | PT | PRT | 620 |
Q-Z
| Country | Alpha-2 | Alpha-3 | Numeric |
|---|---|---|---|
| Qatar | QA | QAT | 634 |
| Romania | RO | ROU | 642 |
| Russia | RU | RUS | 643 |
| Saudi Arabia | SA | SAU | 682 |
| Serbia | RS | SRB | 688 |
| Singapore | SG | SGP | 702 |
| Slovakia | SK | SVK | 703 |
| Slovenia | SI | SVN | 705 |
| South Africa | ZA | ZAF | 710 |
| South Korea | KR | KOR | 410 |
| Spain | ES | ESP | 724 |
| Sri Lanka | LK | LKA | 144 |
| Sweden | SE | SWE | 752 |
| Switzerland | CH | CHE | 756 |
| Taiwan | TW | TWN | 158 |
| Thailand | TH | THA | 764 |
| Turkey | TR | TUR | 792 |
| Ukraine | UA | UKR | 804 |
| United Arab Emirates | AE | ARE | 784 |
| United Kingdom | GB | GBR | 826 |
| United States | US | USA | 840 |
| Uruguay | UY | URY | 858 |
| Venezuela | VE | VEN | 862 |
| Vietnam | VN | VNM | 704 |
| Zimbabwe | ZW | ZWE | 716 |
Best Practices
1. Always Use Alpha-2 Codes
// β
Good - Use alpha-2 (most standard)
const country = 'US';
const locale = 'en-US';
// β Avoid - Using full names
const country = 'United States'; // Ambiguous, translation issues
// β Avoid - Using numeric codes
const country = 840; // Less readable, harder to maintain
2. Validate Country Codes
const validCountryCodes = new Set([
'US', 'GB', 'CA', 'AU', 'DE', 'FR', 'JP', // ... all valid codes
]);
function isValidCountryCode(code) {
return validCountryCodes.has(code.toUpperCase());
}
// Usage
if (!isValidCountryCode(userInput)) {
throw new Error('Invalid country code');
}
3. Store Codes, Display Names
// β
Good - Store code in database
{
"user_id": 123,
"country": "US", // Store code
"created_at": "2025-01-15"
}
// Display full name in UI
const countryNames = {
'US': 'United States',
'GB': 'United Kingdom',
'CA': 'Canada'
};
function displayCountry(code) {
return countryNames[code] || code;
}
4. Handle Special Cases
// UK vs GB
function normalizeCountryCode(code) {
const normalized = code.toUpperCase();
// Handle common variations
if (normalized === 'UK') return 'GB'; // UK β GB
if (normalized === 'USA') return 'US'; // USA β US (if expecting alpha-2)
return normalized;
}
// Usage
const country = normalizeCountryCode('UK'); // Returns 'GB'
5. Consider User Location
// Auto-detect user's country
async function detectUserCountry() {
try {
const response = await fetch('https://ipapi.co/json/');
const data = await response.json();
return data.country_code; // e.g., 'US'
} catch (error) {
return 'US'; // Default fallback
}
}
// Pre-select in form
const userCountry = await detectUserCountry();
document.getElementById('country').value = userCountry;
6. Localization
// Display country names in user's language
const countryNames = {
en: {
'US': 'United States',
'FR': 'France',
'DE': 'Germany'
},
es: {
'US': 'Estados Unidos',
'FR': 'Francia',
'DE': 'Alemania'
},
fr: {
'US': 'Γtats-Unis',
'FR': 'France',
'DE': 'Allemagne'
}
};
function getCountryName(code, language = 'en') {
return countryNames[language]?.[code] || code;
}
console.log(getCountryName('US', 'es')); // "Estados Unidos"
Common Issues and Solutions
Issue 1: UK vs GB
Most Common Mistake: Using UK instead of the official GB code. While many systems accept UK, the official ISO code is GB (Great Britain).
// Always normalize
function getOfficialCode(code) {
return code === 'UK' ? 'GB' : code;
}
Issue 2: Country Name Changes
Countries occasionally change names or codes. Examples:
- Swaziland β Eswatini (SZ remains the same)
- Macedonia β North Macedonia (MK remains the same)
- Burma/Myanmar (both MM used)
Solution: Keep your country list updated and use codes, not names.
Issue 3: Disputed Territories
Some territories have codes but may not be universally recognized:
- Taiwan (TW) - Recognized by ISO but politically complex
- Palestine (PS) - Observer state
- Kosovo (XK) - Temporary code
Solution: Be aware of your target audience and handle sensitively.
Summary
ISO 3166 country codes are essential for international web development. Always use alpha-2 codes for consistency, validate user input, and keep your country data updated.
Key Takeaways:
β
Use alpha-2 codes (US, GB, CA) for most applications
β
Store codes in database, display full names in UI
β
Always validate country codes against official list
β
Use GB for United Kingdom, not UK
β
Consider localization for country names
β
Auto-detect user's country when possible
β
Keep country data updated with ISO changes