Start with one carbon and give it four hydrogens: methane, CH₄, the main gas in a kitchen stove. Link two carbons and fill the remaining bonds with hydrogen: ethane, C₂H₆. Three carbons give propane, C₃H₈. Each extra carbon adds a CH₂ unit, so alkanes follow CnH2n+2; for octane, n=8 gives C₈H₁₈. Longer chains have stronger dispersion forces, so alkanes move from gases (1 to 4 carbons) to liquids like petrol (roughly 5 to 12) to waxy solids (about 20 and above).
If two neighbouring carbons share a double bond, each needs one fewer hydrogen: ethene is C₂H₄, and alkenes follow CnH2n. A triple bond removes two more: ethyne (acetylene, the welding gas) is C₂H₂. These are the unsaturated hydrocarbons. Their multiple bonds can open and add other atoms, which is why ethene quickly turns orange bromine water colourless while ethane leaves it orange.
The definition is strict: only carbon and hydrogen. Ethanol, C₂H₅OH, has a chain much like ethane's, but its oxygen makes it an alcohol, not a hydrocarbon. Glucose and PVC are carbon-based too, but their oxygen or chlorine rules them out. Read every symbol in the formula before you apply the label.
Think of it like this. A hydrocarbon is a carbon chain dressed only in hydrogen: carbons hold hands in a line, and every spare hand grabs a hydrogen. Where two carbons hold on with two hands at once (a double bond), each has one fewer hand free for hydrogen, which is why alkenes carry fewer H atoms than alkanes. Add any other element and it stops being a hydrocarbon.
Core idea. A hydrocarbon contains only carbon and hydrogen; its carbon-carbon bonds (single, double, or triple) set its family and its hydrogen count, and complete combustion of any hydrocarbon gives carbon dioxide and water.