The temperature of the earth is a balance between the heat it gets from the sun and the heat it radiates back out into space. Gases in the atmosphere absorb most of the heat that would normally be radiated out into space, and re-radiate it in all directions, including back towards the earth. If this didn't happen, then at night there would be nothing to keep heat in, and we'd get very cold. Several different gases in the atmosphere help keep heat in, including water vapour, carbon dixoide and methane - these are called "greenhouse gases."