The basic need for understanding octane ratings comes down to
one statement for firefighting....
"Class B rated foams work equally on
all three common gasoline Octane ratings".
Internal combustion engines are designed to burn gasoline in a controlled process called deflagration. But in some cases, gasoline can also combust abnormally by detonation, which wastes energy and can damage the engine. One way to reduce detonation is to increase the octane content of the gasoline, which is expressed by its octane rating.
Normally a spark plug fires, providing the "HEAT" side of the tetrahedron. Heat from compression may be enough to "fire" the fuel vapor which will not be properly timed with the complete engine cycle.
A higher octane fuel is needed with a higher compression such as in a performance car. If you have to run a higher octane fuel than your owner's manual calls for to reduce knocking and pinging, it could be a sign of several other engine problems.