The remote control codes are just a set of numbers with one number assigned to each function of the device. How those numbers get sent to the device and in what format depends on the protocol in use.
The most widely used protocol is NEC1 (now superseded by NEC2 which is backwards compatable with NEC1). There are of course dozens of others, but the principle is the same - it's just a sequence of numbers sent on an IR carrier frequency.
With NEC1/2, the first number sent is a unique bit pattern that basically tells the device 'Get Ready - a command is coming'.
The next set of numbers are a 'device code' and 'subdevice code'. Every manufacturer has a device code and each of their components has a subdevice code; eg. Onkyo's device code is 210 and the subdevice code for the receiver is 109. If the receiver sees 210, it knows the following command should be for an Onkyo component. If the next number it sees is 109, it knows the command is for itself. If it doesn't recognize the device code, it will ignore everything that follows. If it recognizes the device code, but the subdevice code is not for itself, then it will either ignore what follows or pass it along to another device that is connected via its IR Out jack or another proprietary scheme like Onkyo's Remote Interactive jack.
The number that follows all of that is the actual number for the function you are asking it to perform; eg 183 for Volume Up and 187 for Volume Down for Onkyo.
A pre-programmed remote has a table that stores all of that information. You access the correct table by punching in the 'setup code'. So on a URC All-for-One remote control, when you enter setup code 135 it retrieves the details that say the protocol is NEC1, the device code is 210, the subdevice code is 109, and all of the other numbers for the functions the device can perform. A different brand remote may have the same details but use a different setup code.
The catch is that manufacturers sometimes change things around. That's why there is no guarantee that the code table in the remote will work for any particular device even if a code is listed. Sticking with Onkyo as an example because that is what I own and what I am most familiar with - newer receivers have discrete power codes (separate number for on and off instead of one number that toggles the state). BUT, the code for On is the same as the old code for power toggle. So an older universal remote with codes for Power Toggle will turn the receiver On, but not Off!
Pre-programmed remotes may be convenient for setup, but you sometimes run into those types of little problems. Harmony's approach is to constantly upgrade their database to help alleviate those problems, but I still prefer to learn every command from the original remote.