Each key has what is called an immobilizer chip in it. That chip has a set code. Kind of like a garage door opener. The car has a way of detecting the code in each key. For every new key you buy the dealer has to hook up there scanner to your carr and access the Immobilizer system. Than tell the car to recognize that key. Only the dealer has this software since its much like a security system.
The other advantage is that in the old days people us to break apart the ignition locks ans start the car. Well if the immobilizer never gets a signal from the car than it will never start. Basically it shuts down the system.
The system also has the abillity to delete keys. Lets say your keys got stolen well the dealer can go into the system and remove the key so that person cannot come steal your car. They can get into it but not drive it away.
I think the key itself is 15-30 dollars and usually costs 1 hour labor to program.