This article is from the Gasoline FAQ, by Bruce Hamilton with numerous contributions by others.
Traditionally, the greatest tendency to knock was near 13.5:1 air-fuel
ratio, but was very engine specific. Modern engines, with engine management
systems, now have their maximum octane requirement near to 14.5:1. For a
given engine using gasoline, the relationship between thermal efficiency,
air-fuel ratio, and power is complex. Stoichiometric combustion ( air-fuel
ratio = 14.7:1 for a typical non-oxygenated gasoline ) is neither maximum
power - which occurs around air-fuel 12-13:1 (Rich), nor maximum thermal
efficiency - which occurs around air-fuel 16-18:1 (Lean). The air-fuel ratio
is controlled at part throttle by a closed loop system using the oxygen sensor
in the exhaust. Conventionally, enrichment for maximum power air-fuel ratio
is used during full throttle operation to reduce knocking while providing
better driveability [38]. An average increase of 2 (R+M)/2 ON is required
for each 1.0 increase (leaning) of the air-fuel ratio [111]. If the mixture
is weakened, the flame speed is reduced, consequently less heat is converted
to mechanical energy, leaving heat in the cylinder walls and head,
potentially inducing knock. It is possible to weaken the mixture sufficiently
that the flame is still present when the inlet valve opens again, resulting
in backfiring.
 
Continue to: