Global warming occurs when greenhouse gases, such as carbon dioxide, nitrous oxide, and methane trap heat inside the earth's atmosphere.
Think about what happens when you open your car door after the windows have been rolled up on a hot day. Heat from the sun enters the car, but the frame of the car prevents it from escaping.
To a small extent, this is a representation of what happens during global warming. Burning fossil fuels like petroleum and deforestation both contribute to the problem.