Crude oil is refined by distilling it in a fractional distillation tower.
Depending on the fuel source, a slightly different amount of energy is obtainable per gram of fuel. The following graphic illustrates this with several fuels. Note the graphic will split if your column width is on a smaller screen.
So methane is the big winner among all the carbon-based fuels. However, hydrogen gas puts all these hydrocarbons to shame as far as bang for your buck or in this case, bang for your gram. H2 gas provides about 121 kJ/g when it is burned which is 2.7× more than the energy output for gasoline. So should we all be burning hydrogen instead of gasoline? That is a complicated question and has a lot of different issues all wrapped up inside it. I will allow that question to be answered elsewhere - but the numbers don't lie, hydrogen is more bang for your mass-based buck.
Because the money is where the gasoline fraction is, other fractions can be converted into gasoline. Cracking is the process where a large hydrocarbons that are in the C15 to C20 range are broken into two smaller pieces. A "perfect" example of this would be the following reaction:
C16H34 → C8H18 + C8H16
There is thermal cracking which is done with heat alone - high temperatures (typically between 400 and 450 °C) with no oxygen present will result in the breaking into the two new hydrocarbons. The process isn't always "perfect" sometimes your "crack" is a little off the mark like here...
C16H34 → C10H20 + C6H14
Far more efficient (both energy-wise and specificity) is catalytic cracking which can be done much closer to the boiling point temperature (much lower temperature) and is much more specific on how the molecule breaks. Special catalysts are developed and continue to be developed to better the production of the better burning gasoline molecules (higher octane ratings).
Yet another catalyst and a set of optimal conditions can be used to breakdown undesirable linear chain hydrocarbons and remake them into highly branched and even aromatic hydrocarbons. This process is called catalytic reforming. Octane ratings of a gasoline are lowered by linear chain hydrocarbons. The optimal or at least the compound with a 100 as an octane rating is isooctane which is really 2,2,4-trimethylpentane. It is shown below compared to straight-chain n-octane.
Catalytic reforming can be tailored to get the maximum octane ratings out of all kinds of feedstocks of crude oil. All of this (along with the cracking from above) allows for a higher percentage yield of high octane gasoline from a barrel of crude oil.