Before the International Air Transport Association established airport codes, pilots used the two-letter abbreviation of whatever city they needed to communicate with. The two-letter codes were established by the National Weather Service. The system quickly became unsustainable for airplane pilots, and a three-letter system was created.
In the beginning, it was simple. The IATA airport code was the first three letters of whatever city the airport was located in. Some cities made the full switch, but some cities kept the original two-letter codes and just added "X" as the third letter. To make things confusing, some cities weren't represented by the first three letters of their names, but by a random three letters in the name instead. For example, Warsaw's international airport is WAW instead of WAR.
To make things more confusing, some cities have multiple airports. Places like New York City and London have so many airports that no single one can claim NYC or LON as an airport code. This led to airport codes based on the actual name of the airport, like Chicago's O'Hare Airport. But if that wasn't confusing enough, some airports, like O'Hare, undergo name changes and the airport code is never updated. And on top of that, some cities, like Bombay and Peking, simply change their names. Needless to say, some IATA airport codes can't be figured out with logic and reason. They can only be memorized. How many international airport codes do you know?