Country and Region Code Tools

Country code tooling: separates ISO 3166-1 alpha-2, alpha-3 and numeric codes, explains that ccTLDs, dialling codes and language codes are different systems, and covers the timezone root cause of off-by-one-day date bugs.

The question "the country code for China" has at least three answers, depending on which system you are looking in.

Approach Comparison

SystemExample (China)Primary use
ISO 3166-1 alpha-2CNDomains and most system identifiers
ISO 3166-1 alpha-3CHNUnited Nations, some aviation and shipping
ISO 3166-1 numeric156Statistics and legacy systems
ccTLD.cnCountry-code top-level domain
International dialling code+86Telephone numbers
Language codezhISO 639 language identifier
Complete localezh-CNLanguage plus region
Unallocated country codeCN (root zone)See the IANA root zone record

Edge Cases

  • ccTLDs do not map one-to-one with ISO codes: .uk is the UK domain while the ISO alpha-2 is GB.
  • Dialling codes are not country codes either: +7 is shared by Russia and Kazakhstan.
  • A language code (zh) combined with a region code (CN) forms the complete locale identifier zh-CN.
  • Daylight saving transitions mean the offset from UTC shifts twice a year within a single zone.

Common Pitfalls

  • Storing +86 in a column intended for ISO country codes, mixing two systems in one table.
  • Matching the UK on ISO alpha-2 when the actual value is GB rather than UK, so every lookup fails.
  • Formatting a UTC timestamp as if it were local time, landing on the wrong day.
  • Adding or subtracting days on date strings, bypassing timezone and DST rules and producing wrong dates.

Related Tools