In addition to airports having their own code, countries also have their own code. Countries get a code for the same reason that airports get their code, namely for data processing and communications.
A country code is a short alphabetic or numeric geographical code designed for the recognizability of countries and dependent areas. The term country code frequently refers to international dialling codes (the E.164 country calling codes. Various systems have been designed to create the codes. Country codes are almost everywhere the same so it's easily recognisable which country is intended.
The most used code that is considered the standard for nearly all countries in the world is the ISO3166-1. ISO 3166-1 is part of the ISO 3166 standard published by the International Organization for Standardization (ISO) and defines codes for the names of countries, dependent territories, and special areas of geographical interest.
The ISO 3166-1 standard is the first part of ISO 3166 and records all countries in the world with unique two-letter country codes (alpha-2), three-letter country codes (alpha-3) and three-digit country codes (numeric-3).
ISO 3166-1 alpha-2
The two-letter code is also used as an internet top-level domain - except for the code from the United Kingdom, where the top-level UK is used instead of GB, and the United States, where mainly .COM is used instead of US.
ISO 3166-1 alpha-3
The three-digit country codes always remain the same over a specific geographical area. If two countries split or merge, new numeric codes are issued. With a name change of a country, the three-digit country code remains the same.
Country codes vs language codes
Country codes should not be confused with ISO 639 language codes. For example, 'sv' is the language code for Sweden but also the country code for El Salvador. It is therefore recommended to write the ISO 3166 country codes in upper case and the ISO 639 language codes in lower case.