There is a 3 letter code assigned to each airport. Generally speaking, airport codes are named after the first three letters of the city in which it is located—ATL for Atlanta, DEN for Denver, etc.

Airport codes arose out of the convenience that it brought pilots for location identification in the 1930s. Initially, pilots in the United States used the two-letter code from the National Weather Service (NWS) for identifying cities. This system became unmanageable for cities and towns without an NWS identifier, and 3 letters gives a lot more possibilities- thus a three-letter system of airport codes was implemented. It is sometimes easy to guess and sometimes not.

So why is Maui, or Kahului airport named OGG? It’s not because KAH was already taken. It may have to do with the ICAO (International Civil Aviation Organization) 4 letter code used by air traffic control, which for Kahului, Maui is PHOG. In 1957 the ICAO adopted that name in honor of Jimmy Hogg a Hawaiian airline pilot and aviation pioneer.

More Info: en.wikipedia.org