A key code is merely a number which is assigned to a particular key, representing the actual shape of that key. Because it represents the actual key, it also represents the components of the lock associated with that key. The simplest key code would just be the actual depths of a key. A more complex code might be an alpha-numeric which not only represents the cuts, but also the spacing of the cuts and particular keyblank required.
Who Needs Key Codes?
The original intent of key codes was for use in the manufacturing process when the assembly of locks became disassociated with the keys themselves. In other words, the process of building the lock did not require the lock's actual key, but possibly just one used for its production. The lock could then be stamped with the code number and processed further without the key. Keys and locks could then be joined at the end of the processes.
Early Problems with Key Codes
One of the early problems which involved key codes was when the code number was stamped on the face of the lock the number was clearly available to anyone who could see the lock. If the listing of key codes became compromised, it might be possible for an unauthorized person to have a key made.