A fun mnemonic to memorize the first four hydrocarbons:

M… methane, 1 carbon
E… ethane, 2 carbons
P… propane, 3 carbons
B… butane, 4 carbons
For any hydrocarbon, if you know the number of carbons in the carbon chain, you can calculate the number of hydrogens by doubling the number of carbons and adding 2. For example, octane, which has 8 carbons, has 2*8 + 2 = 18 hydrogens.