The sun supplies heat to Earth, but some of it seeks to escape into space. The gases in the atmosphere, such as carbon dioxide and methane, act as a warm blanket, trapping some of the heat and keeping the Earth at an optimal temperature for plants, animals, and humans to exist.