Carbon Dioxide keeps the atmosphere warm by absorbing infra-red heat (from the sun) rising from the warm earth's surface. This heat remains in the atmosphere heating other greenhouse gases and even heating the earth's surface again. This is called the greenhouse effect.
Certain atmospheric gasses, known as "greenhouse gases", absorb IR, then re-emit it back into the atmosphere. Some percentage of this re-emitted IR (after a long sequence of re-absorptions and re-emissions by other greenhouse gas molecules) eventually works its way back down to the lower atmosphere and is said to "warm" the surface. This is the "greenhouse effect". The "greenhouse effect", in and of itself, is a completely natural thing, and also a very good thing. Without it, the surface would be far too cold for life as we know it to exist.
At this point, it must be empasized that carbon dioxide (CO2) is just one of many so-called "greenhouse gases". It is not the most important, nor the most abundant. That distinction belongs to water vapor. Even without carbon dioxide, water vapor alone would cause enough of a greenhouse effect to keep us very near the warm temperatures that we enjoy. Also worth emphasizing is the fact that greenhouse gasses do not "trap" IR. They absorb, then re-emit the IR, in a completely random direction. It could go up, down, sideways, or any direction in between. Re-absorption by other greenhouse gas molecules complicates the path and destination of an individual unit of IR, but what it all boils down to is that something less than half of the IR absorbed by greenhouse gasses eventually finds its way back to the surface, with the remainder escaping into space.
Though the greenhouse effect itself is completely natural, and very beneficial, global warming scientists believe that anthropogenic (man-made) emissions of carbon dioxide (mostly from burning fossil fuels) have increased CO2 in the atmosphere to a point where we are now experiencing an "enhanced greenhouse effect". This artificial enhancement of the greenhouse effect is causing significant warming of the atmosphere and the surface, over and above what the natural greenhouse effect causes.