Sun emits heat and light, a part of which is absorbed by the atmosphere and the rest of it is reflected back. This prevents the earth from getting too hot during the day time. Similarly, during the night time, the trapped heat in the atmosphere prevents the earth from getting too cold. In this way the atmosphere help to maintain the right temperature on the earth.