Key programming

Just for curiosity’s sake. When you program the keys, are you really programming the key to match the car or the car to match the key? Which one has the ‘parent’ signal (car or key) and which is changed to match the other. I’ve just had to program two keys for my XF after I laundered the only key I had and it got me wondering if your actually telling the car to accept the signal from the keys or changing the key to match the car. I suspect the key has a unique output and what you’re actually doing is programming the car to accept that.
I didn’t cancel the keys before programming the new ones and I probably should have as out there, there is probably a key that will open and start my car.
So if it’s the car computer that is programmed I assume there would be no trouble if I erased all keys and re-programmed the car to accept my new ones again.