ISO 3166 Country Code Validator
Validate ISO 3166-1 alpha-2 / alpha-3 country codes and resolve country name.
ISO 3166-1: the global standard for country codes
ISO 3166-1 is the part of the ISO 3166 family that lists country codes for every sovereign nation, dependent territory and special area recognized by the United Nations Statistics Division. It is maintained by the ISO 3166 Maintenance Agency in Geneva and is the silent backbone of i18n, e-commerce shipping forms, analytics, banking (it feeds the first two characters of IBAN) and domain names (ccTLDs like .br, .us, .de).
The standard publishes three parallel representations of every country, so applications can pick the one that best fits their channel. They are kept in lockstep: changing one triggers an update across the three.
The three variants
- Alpha-2: two uppercase letters (
BR,US,GB,DE,FR,JP). The most common form online โ used in URLs, locale identifiers, ccTLDs and HTMLlangattributes. - Alpha-3: three uppercase letters (
BRA,USA,GBR,DEU,FRA,JPN). Preferred by sport governing bodies (FIFA, IOC have their own codes but reference alpha-3) and IATA-adjacent systems. - Numeric: three digits (
076BR,840US,826GB,276DE). Script-agnostic, immune to RTL/LTR issues and the only form usable when alphabetic charsets are not available.
Exceptional and user-assigned reservations
Not every two-letter combination is a country. ISO reserves some codes for special purposes: EU is exceptionally reserved for the European Union, UK is exceptionally reserved (the United Kingdom's official ISO code is GB โ "United Kingdom of Great Britain and Northern Ireland"). XK for Kosovo is a user-assigned code, not officially in ISO 3166-1. Indeterminate reservations like AN (Netherlands Antilles, retired 2010) stay blocked for at least 50 years.
ISO 3166-2: subdivisions inside a country
When you need to identify a state, province or region, switch to ISO 3166-2. The format is COUNTRY-SUBDIVISION: BR-SP (Sao Paulo), BR-RJ (Rio de Janeiro), US-CA (California), US-NY (New York), GB-ENG (England), DE-BY (Bavaria). Shipping APIs, tax engines and address autocompletes typically use 3166-2 internally.
Codes that changed and codes that never do
Country codes change rarely but it happens: Eswatini kept SZ when it renamed from Swaziland (2018), Czechia kept CZ after the short-form rename (2016), North Macedonia stayed MK (2019) โ short names changed in the registry but the codes stood. New entries do appear: South Sudan received SS / SSD / 728 in 2011. Always pin the version of your ISO 3166 library and review release notes once a year.
Where ISO 3166-1 shows up in the stack
- HTML
langattribute:<html lang="pt-BR">โ BCP 47 reuses ISO 3166-1 alpha-2 as the region subtag. - URL locale segments:
/pt-br/(lowercase, recommended by Google) or/pt-BR/(mixed case, RFC 5646 canonical). - Shipping and checkout forms: country dropdowns send alpha-2 or alpha-3 to payment gateways.
- Google Analytics 4 geo reports: countries returned as ISO 3166-1 alpha-2.
- GDPR data residency: data localization rules keyed on alpha-2 country code.
- IBAN: the first two characters of an IBAN are the ISO 3166-1 alpha-2 of the bank's country.
- Phone country codes: not ISO โ that is ITU-T E.164 (+55 Brazil, +1 USA, +44 UK).
Working with ISO 3166-1 in code
Popular libraries:
- JavaScript:
iso-3166,i18n-iso-countries,country-liston npm. - Python:
pycountry(covers 639, 3166, 4217, 15924). - Java:
java.util.Localeexposes country codes viagetCountry()(alpha-2) andgetISO3Country()(alpha-3). - .NET:
RegionInfoclass wraps alpha-2 and alpha-3.
Example in JavaScript:
const countries = require('i18n-iso-countries')
countries.getName('BR', 'en') // "Brazil"
countries.getAlpha3Code('Brazil', 'en') // "BRA"
countries.getNumericCode('BR') // "076"
Common pitfalls
- UK vs GB:
UKis informal and exceptionally reserved;GBis the official ISO code. UseGBin any system that must round-trip with banks, IATA or government APIs. - EU is not a country: the
EUcode is reserved but does not represent a sovereign state โ never store it as a citizenship value. - Northern Ireland: part of the UK / GB but with separate flag and political identity. Use ISO 3166-2 (
GB-NIR) when granularity matters. - Kosovo: lacks an official ISO 3166-1 code due to political dispute; user-assigned
XKis a de-facto convention. - Hong Kong, Macau, Taiwan: have their own ISO codes (
HK,MO,TW) despite political sensitivity.
Brazil specifics
Brazil is identified as BR (alpha-2), BRA (alpha-3) and 076 (numeric). Locale pt-BR distinguishes Brazilian Portuguese from European Portuguese pt-PT. The ccTLD is .br (administered by NIC.br / Registro.br). All 26 states + the Federal District have ISO 3166-2 codes from BR-AC (Acre) to BR-TO (Tocantins).
FAQ
Should I use alpha-2 or alpha-3 codes?
For most web contexts (URL locales, HTML lang, GA4, checkout forms), alpha-2 is the de facto choice. Alpha-3 is better when you need disambiguation across locales or compatibility with sport bodies. Numeric is the safe pick for script-neutral systems.
Why is the UK code GB and not UK?
Because the country's official ISO name is "United Kingdom of Great Britain and Northern Ireland". ISO 3166-1 derived the alpha-2 from "Great Britain". UK is informally reserved but not the canonical code.
Does the ISO 3166 list change often?
Rarely. New additions average less than one per decade (last was South Sudan in 2011). Name changes are more frequent but seldom break the codes themselves. Subscribe to the ISO Online Browsing Platform feed for notifications.
Does this tool query an external API?
No. Validation runs locally against the bundled ISO 3166-1 table. Nothing is sent to a server.
Related Tools
CPF Validator
Validate Brazilian CPF numbers instantly using the official algorithm. Useful for testing document validation in applications. No data sent to servers.
Batch CPF Validator
Validate a list of CPFs (one per line) and see which are valid and which are not. No data sent to servers.
Batch CNPJ Validator
Validate a list of CNPJs (one per line) with a summary of valid, invalid and total. No data sent to servers.