Crude oil is heated until it boils. As a gas it floats upwards.
As the gas goes higher up and further from the heat source the temperature decreases.
When a compound reaches it condensing point it will condense into a liquid and be collected.
This is known as fractional distillation, and groups with similar condensing temperatures are known as fractions; each fraction is a different substance.