In it's simplest terms, the hex code is the unique identifier of the aircraft's transponder. Transponders are the hardware on board the aricraft which broadcast the aircraft's position and other information specific the aircraft. All aircraft are required to have a transponder to operate in controlled airspace (airspace which is monitored by Air Traffic Control for safe aircraft seperation).
It's called a "hex code" due to the hexidecimal formatting of the code. Hexidecimal uses 16 distinct symbols, most often the symbols "0"–"9" to represent values 0 to 9, and "A"–"F" (or alternatively "a"–"f") to represent values from 10 to 15. From https://en.wikipedia.org/wiki/Aviation_transponder_interrogation_modes#ICAO_24-bit_address : "Mode S equipped aircraft are assigned a unique ICAO 24-bit address or (informally) Mode-S "hex code" upon national registration and this address becomes a part of the aircraft's Certificate of Registration. Normally, the address is never changed, however, the transponders are reprogrammable and, occasionally, are moved from one aircraft to another (presumably for operational or cost purposes), either by maintenance or by changing the appropriate entry in the aircraft's Flight management system."