ISO Country Codes Explained: Alpha-2, Alpha-3, Numeric
Two letters stand for a country on almost every form you fill in, yet many developers only learn the rules behind them after a bug. Why is Germany DE? Why do some systems want three letters instead of two? And how does a pair of letters turn into a flag emoji? This guide explains the ISO 3166 family of country codes, how they are used in software and the mistakes worth avoiding.
Three codes for every country
The international standard ISO 3166-1 gives each country or territory three codes:
- Alpha-2 โ two letters, the most widely used:
US,DE,JP. - Alpha-3 โ three letters, easier to recognize at a glance:
USA,DEU,JPN. - Numeric โ three digits, independent of any alphabet:
840,276,392.
Alpha-2 is the default for web forms, shipping and payments. Alpha-3 appears in some passports and sports results, while numeric codes are handy when letters could cause confusion across writing systems.
Why some codes look strange
Codes are often based on a countryโs own name rather than its English one:
- DE โ Germany, from Deutschland.
- ES โ Spain, from Espaรฑa.
- CH โ Switzerland, from the Latin Confoederatio Helvetica.
- HR โ Croatia, from Hrvatska.
- ZA โ South Africa, from the Dutch Zuid-Afrika.
Codes also change with history. When a country dissolves or renames itself, codes are retired or replaced โ Czechoslovakiaโs CS and the Soviet Unionโs SU are no longer active, which is why old databases sometimes contain codes that modern validators reject.
Domains, flags and subdivisions
Country-code internet domains mostly follow alpha-2: .de, .jp, .br. The best-known exception is the United Kingdom, which uses .uk even though its ISO code is GB.
Flag emoji are built from the same codes. Unicode defines 26 โregional indicatorโ letters, and a supporting device shows the right flag when two of them appear together, so the letters F and R become the French flag. Some systems show only the letters, which is why flags look different across platforms.
For regions inside a country there is ISO 3166-2, which adds a suffix to the alpha-2 code: US-CA for California or CA-ON for Ontario.
Generate country codes with RandNow
The Random Country Code Generator above is a quick source of realistic values:
- Enter a number from 1 to 100 in How many?.
- Press Generate. Each result shows the flag, the code and the country name, for example ๐ท๐ด RO (Romania).
- Copy the list or export it as CSV, JSON or TXT for fixtures, dropdown mockups or a geography quiz.
Each pick is independent, so a large batch can repeat a code. Everything runs in your browser with the Web Crypto API and nothing is stored. To see full country names first, try:
Pitfalls developers should avoid
- Case: store codes in uppercase and normalize input, because โdeโ and โDEโ should match.
- Language versus country:
enis a language code;GBorUSare countries. Locales such asen-GBcombine both. - Hard-coded lists: codes are added and retired over time, so keep your list updatable.
- Special cases: Kosovo is commonly represented by
XK, a code from the user-assigned range rather than an official ISO assignment. Decide how your system handles it. - Display names: store the code, not the name, and translate names for each userโs language.
Other country codes you will meet
ISO codes are not the only country abbreviations in daily life, and mixing them up is a classic error:
- Sports codes: the Olympic movement uses its own three-letter codes, such as
GERfor Germany andSUIfor Switzerland, instead of the ISO alpha-3DEUandCHE. - Vehicle stickers: international vehicle registration codes differ again โ Germany is simply
D. - Currency codes: ISO 4217 currency codes often begin with the countryโs alpha-2 code, as in
JPYorCHF, but they are a separate standard.
When a spreadsheet arrives with a โcountryโ column, check which system it uses before importing it.
Pro tips
- Use alpha-2 as your internal key unless a partner system demands alpha-3.
- Validate against a maintained list rather than a pattern like two capital letters.
- Test flag display on several devices, since some show letters instead of flags.
- Quiz yourself on codes that do not match the English name, such as DE, ES and CH.
Frequently asked questions
Who maintains the ISO country codes?
The ISO 3166 Maintenance Agency, part of the International Organization for Standardization, publishes and updates the official lists.
Should I use alpha-2 or alpha-3 codes?
Alpha-2 is the most common choice for web forms, payments and shipping. Use alpha-3 only when a partner system or document format requires it.
Is a country code the same as a calling code?
No. Calling codes such as +44 or +49 are assigned separately for telephone numbers and do not follow the ISO letter codes.