this is a complicated question that needs some basic fuel composition understanding to understand
below is a copy/paste from wiki:
Higher octane ratings correlate to higher activation energies. Activation energy is the amount of energy necessary to start a chemical reaction. Since higher octane fuels have higher activation energies, it is less likely that a given compression will cause autoignition.
It might seem odd that fuels with higher octane ratings are used in more powerful engines, since such fuels ignite less easily. However, an uncontrolled ignition is not desired in a spark ignition engine.
A fuel with a higher octane rating can be run at a higher compression ratio without causing detonation. Compression is directly related to power and to thermodynamic efficiency (see engine tuning), so engines that require higher octane usually deliver more motive power and do more work for a given BTU or calorie of fuel. Engine power is a function of the fuel, as well as the engine design, and is related to octane rating of the fuel. Power is limited by the maximum amount of fuel-air mixture that can be forced into the combustion chamber. When the throttle is partially open, only a small fraction of the total available power is produced because the manifold is operating at pressures far below atmospheric. In this case, the octane requirement is far lower than when the throttle is opened fully and the manifold pressure increases to atmospheric pressure, or higher in the case of supercharged or turbocharged engines.
Many high-performance engines are designed to operate with a high maximum compression, and thus demand high-octane premium gasoline. A common misconception is that power output or fuel mileage can be improved by burning higher octane fuel than a particular engine was designed for. The power output of an engine depends in part on the energy density of its fuel, but similar fuels with different octane ratings have similar density. Since switching to a higher octane fuel does not add any more hydrocarbon content or oxygen, the engine cannot produce more power.
However, burning fuel with a lower octane rating than required by the engine often reduces power output and efficiency one way or another. If the engine begins to detonate, that reduces power and efficiency for the reasons stated above. Many modern car engines feature a knock sensor – a small piezoelectric microphone which detects knock, and then sends a signal to the engine control unit to retard the ignition timing. Retarding the ignition timing reduces the tendency to detonate, but also reduces power output and fuel efficiency. Because of these systems, under certain condtions of high load and high temperature, a given car may produce more power with a higher octane fuel. With a lower octane fuel, these engines systems will be reducing power to control detonation, while with a higher octane fuel, the engine will produce full power. And some modern high performance engines are actually optimized for higher than pump premium (93 AKI in the US). The 2001 - 2007 BMW M3 with the S54 engine is one such car. Car and Driver magazine dyno tested a car and found that the power output increased as the AKI was increased up to approximately 96 AKI. Also, these systems can result in higher fuel mileage for cars designed for the higher octane fuels.
Most fuel stations have two storage tanks (even those offering 3 or 4 octane levels), and you are given a mixture of the higher and lower octane fuel for the intermediate grades. Premium is fuel from the higher octance tank, the minimum grade sold, is sfuel from the lower octane tank. Purchasing 91 (where offered) simply means more fuel from the higher octane tank than purchasing 89; the detergents in the fuel are often the same. But for some producers, the additive package is different between the higher and lower octane rating.