The general formula for a saturated hydrocarbon or alkane is CnH2n+2. So, for methane, n=1 and 2n+2 = 4, CH4. For butane, n=4, 2n+2 = 10, C4H10.
Unsaturated compounds also exist. When a hydrocarbon has one double bond, the generic formula is CnH2n. An example is ethene, C2H4.
Another way to have a molecule with formula CnH2n is to introduce a ring in the structure.
One can predict the number of multiple bonds (pi bonds) and rings by dividing the difference between the number of hydrogens predicted for a saturated hydrocarbon and the actual number of hydrogens by 2. The result is the sum of the number of rings and pi bonds.