Gasoline is a mixture of hydrocarbon chain molecules with between around 6 to 10 carbons atoms, in a bell curve centered around 8 carbon atoms (octanes). All those molecules aren't just straight carbon chains. Instead, they're in all sorts of configurations (isomers), which results in the gasoline behaving differently depending on its particular mixture of isomers.
Performance of gasoline
Some mixtures can be compressed more than others without accidentally exploding ("knocking"). The more you compress the fuel before igniting it, the more efficient your engine can be. Higher performance cars compress fuels to higher pressures to achieve that performance, and require better fuels so that they don't knock.
Higher octane fuels burn with less chance of "nocking" in the engine. More finely tuned engines are more susceptible to nocking, and need higher octane fuel.
You should always use the fuel that your engine is rated for.
Going lower than the proper octane could damage your engine in the long run.
Going higher than the recommended octane is a waste of money. You will see no benefit in engine life or fuel economy.
The higher octane fuels aren't necessarily higher quality in any measurable way.