Oil and natural gas are part of a group of compounds called hydrocarbons. As you can probably guess from the name, hydrocarbons contain only the elements hydrogen and carbon.
Hydrocarbons have a useful property in that they can form together to form almost limitless chains - short chains will be gas, and long chains will be liquid, which we call oil (or 'petroleum', to use its correct term).
Short chains will be gas as they are light. Longer chains will be things like gasoline, which evaporate easily - that puddle of spilled gasoline that quickly disappeared when you were filling up your car is volatile (which means they are liquid but easily vapourise) hydrocarbons.
Increase the length of the chains and they are heavier and more viscous - what you will know as oil (the stuff you use to lubricate your bike chain or your car engine). Make the chains even longer and you get pitch - the asphalt, bitumen, and tar we use to make our roads are forms of pitch - despite what the environmentalists seem to think, we can't yet walk on the electricity from wind turbines.
Carbon has a valence of 4, which means it can join to four other atoms, while hydrogen has a valence of 1, which means it can only bond with one other atom.
Since a hydrocarbon has to have hydrogen and carbon, with a single carbon atom you must have 4 hydrogen atoms - CH4, aka methane. To work out the valence of any element, just look at the periodic table - as a general rule, the valence of all the elements in one column will be the same. So methane is the simplest hydrocarbon, and doesn't have many atoms so it's light weight - it's a gas. Then if you break off a hydrogen atom from methane's carbon so that the next carbon can join you get C2H6 - ethane. Do it again and you get C3H8 (propane), then again gets you butane (C4H10), pentane (C5H12), hexane (C6H14), heptane (C7H16), octane (C8H18), and so on... the more carbons in the chain, the heavier it is, so it's more likely to be a liquid - a chain with more than 5 carbon atoms will usually be a liquid at room temperature.
In reality there are infinite configurations ('isomers') of hydrocarbons - you can get double bonds between the carbon atoms ('alkenes' - used to make plastics, amongst other things), millions of chains branching off one another, rings of hydrocarbons (like benzene - called 'aromatic' hydrocarbons because they usually smell good), you name it - if it fits with carbon having a valence of 4, and hydrogen 1, it can be probably be found.