How the greenhouse effect warms the surface
Sunlight arrives mostly as visible and near-infrared radiation, passes through the atmosphere, and warms the Earth's surface. The warmed surface re-radiates energy as longer-wavelength infrared. Greenhouse gases such as carbon dioxide, water vapor, methane, and nitrous oxide absorb much of this outgoing infrared and re-emit it in all directions, including back downward.
This trapping keeps the surface considerably warmer than sunlight alone would. Without any greenhouse effect, Earth's average surface temperature would be roughly minus 18 degrees Celsius rather than the habitable average near 15 degrees Celsius.
Natural effect versus enhanced warming
The natural greenhouse effect is essential for life. The concern in climate science is the enhanced greenhouse effect, in which human emissions, chiefly carbon dioxide from burning fossil fuels, raise the concentration of greenhouse gases and increase the amount of infrared trapped.
Atmospheric carbon dioxide has risen from about 280 parts per million before industrialization to over 420 parts per million today, strengthening the effect and driving observed global warming. Water vapor amplifies the warming as a feedback, since a warmer atmosphere holds more of it.