Main page > Data

List of countries and territories

This page offers a list of countries and territories to be used in programs. Similar lists already exist but they are either outdated or only human-readable (everything buried in plenty of HTML, not suitable for import into a program). At least that was the case when I started assembling a list of my own.

Note that it's not exactly clear what constitutes a country. Read David Madore's article How many countries are there in the world? to get an overview of ways to answer the question.

Andrew Patton offers a country list with more details, including information on currencies, capitals and types of dependencies.

Criteria for inclusion

A country or territory is in this list if at least one of the following conditions apply:

  1. It has an ISO 3166-1 alpha 2 (two letter) country code.
  2. It has a United Nations 3 digit numerical code.
  3. It has a country code top level domain (ccTLD) that
    1. exists or
    2. existed in the past but is still in use.
    The second reason is responsible for the USSR still being listed.

The lists

Country list (countries.txt)

An ASCII (7 bit) text file with Unix style line endings. One country per line. Columns within a line are separated by semicolons. Columns for which information is not available have the value NULL, similar to a database dump. The meaning of the columns:

  1. Positive integer ID value, unique within this list. To be used as a primary key in a database.
  2. English name of the country. A compact version of the name is used (so Germany instead of Federal Republic of Germany).
  3. ISO 3166-1 alpha 2 code for the country.
  4. ISO 3166-1 alpha 3 code for the country.
  5. UN numerical code for the country.
  6. Integer value, either 0 or 1. 1 means sovereign nation, 0 dependent territory of some sort.
  7. Integer value, either 0 or 1. 1 means country still exists, 0 means country does not exist anymore.
  8. If this entry is not sovereign (so the sixth column is 0) this column can store an integer value pointing to the ID value of the country in this list to which this territory belongs. So, as an example, this column in the entry for French Polynesia stores the ID value of France, because French Polynesia belongs to France.
  9. Country code top level domain.

Country names list (countrynames.txt)

This list stores names of countries in other languages than English. You can use this list to give users a selection of countries to pick from, in their own language.

Status: German and French are the only languages for which names are stored. Please volunteer to translate in your native language!

A UTF-16 text file with Unix style line endings. This file contains empty lines and comments, lines starting with a # character. Both should be skipped by programs reading this file. The file is made up of sections. Each section starts with a comment line which contains the English name of the language for which country names follow. So, # German means that German language country names will follow. Sections are sorted by the English name of the languages in ascending order. The meaning of the columns is as follows:

  1. Integer ID of country. ID values are equal to those used in the country list. In a database, this is a foreign key to the countries table.
  2. Language which was used to describe the country given as a ISO 639 code.
  3. Name of given country in given language.

Continents

See the continents page for supplemental information, including a mapping from countries to continents.

ChangeLog