There are a few different ways to measure the octane rating of gasoline. The most common way is the research method, in which the fuel is tested in a lab engine under controlled conditions. Gasoline can also be tested in an on-board diagnostic (OBD) system, which measures how much compression the fuel can withstand before detonating. The highest octane rating that has been recorded using either method is 130.
The term octane refers to a hydrocarbon molecule with eight carbon atoms. Octane ratings are simply a measure of how heat resistant a particular fuel is. The higher the octane rating, the greater the fuel's resistance to knocking or pinging during combustion.
Detonation occurs when the air/fuel mixture in the cylinders ignites too early. This causes a knocking noise and can damage pistons and valves over time. Higher octane fuels resist this premature ignition, which means they're less likely to cause engine damage over time.
While higher octane ratings offer some advantages, they come at a cost. Higher octane gasolines typically have lower energy content than their lower numbered counterparts and therefore provide less power per gallon. In addition, these fuels often cost more per gallon than their lower octane cousins