Balancing chemical equations can be a little tricky because the number of molecules of all the compounds that are reacting as well as the products have to be in the form of whole numbers. We cannot have fractions for any of them.
To balance CH4 + O2 --> CO2 + H2O,
let's see the number of elements which do not have the same number of atoms on both the sides. Carbon is balanced, hydrogen is not balanced as we have 4 atoms on the left hand side and only 2 on the right hand side. To balance hydrogen double the number of H2O on the right. This makes the total number of oxygen atoms on the right 4. To equate this, double the O2 on the right. This equates the number of atoms of all the elements. The final equation we get is:
CH4 + 2 O2 --> CO2 + 2 H2O