Airline pilot here …
There are actually two (and a half) independent coding systems. One is sponsored by the ICAO (International Civil Aviation Orgranization) and is the governmental designator for airports. The standard has 4 letter/numbers per airport.
All US airports start with K, all Canadian start with C. In other parts of the world, the first letter designates a region (eg M = Central America), the second letter designates the country within region (eg P = Panama) and the last 2 letter/numers designate the specific airport (MPTO = Torrillos International, the airline airport serving Panama City, Panama).
The half-system is the FAA system, which is simply the ICAO designator without the K. For Canadian airports, they drop the C. As a separate matter, most (all?) Canadian ICAO designators have a 2nd letter of Y, which represents a leftover from the system used before the current ICAO system was standardized in the 1950s.
The other system is the IATA (International Air Transportation Association) system. That is used by airlines and give a 3-letter code to all airline-served airports worldwide. IATA codes are not used for ATC purposes, but are used for all airline-to-customer and airline-to-airline purposes.
For US airports, the IATA designator is the same as the FAA designator which is the same as the last 3 letters of the ICAO identifier. So simple, so far… But for non-US airports the IATA designator may have bear no resemblance to the ICAO.
For example, when you fly to London Heathrow, your ticket and baggage tags and whatnot say you’re going to LHR. That’s the IATA code. Meanwhile, up in the cockpit, we’re going to EGLL , the ICAO code for Heathrow. That decodes as Europe, Great Britain, London Area, airport L.
Apparently we’re about to run out of codes and they’re adding a 4th character to the FAA codes, and hence a 5th character to the ICAO code.
AFAIK, the IATA is doing fine on codes for now, but they’ll eventually need more, particularly in areas like China & India that only got 2 letters to work with because they weren’t big players back in the 1950s when the coding scheme was laid out.
All this gets further muddied (for pilots at least) by the need to have designator systems not only for airports, but also for every radio beacon on Earth (thousands), and every pre-defined navigational fix (tens of thousands) on Earth. Fortunately for the customers, they don’t have to mess with this stuff.