There are a few different ways to look at it.
One is that the octane rating is an experimentally-determined number that represents the auto-ignition resistance of a particular batch of fuel. They use a one-cylinder test engine that I think they can change the compression ratio of dynamically, and when they start detecting knocking, they see what the numbers are and they do some math and there is the "octane rating".
One is the origin of the term "octane rating". Originally, at least, the octane scale was how the auto-ignition resistance compared to a mixture of iso-octane and n-heptane fuel. A 100-octane fuel would have the same resistance to auto-ignition as 100% iso-octane, a 50-octane fuel would have the same resistance as a 50/50 mixture of iso-octane and n-heptane, etc.
As for the exact mechanism that makes them resist auto-ignition differently, I'm not sure. It probably has at least as much to do with the shape the molecule is, especially since other isomers of octane (same atoms, arranged differently) have different "octane" values.
For details, see:
Octane rating - Wikipedia, the free encyclopedia
Octane - Wikipedia, the free encyclopedia
I would bet that the exact mixture of chemicals that go into a particular gasoline are a fairly closely-held secret by the manufacturer(s).
-soD