How is Carbon dioxide a greenhouse gas?

The greenhouse effect keeps the earth warm by preventing all the sun's heat escaping back out into space. Carbon dioxide is one of several "greenhouse gases" that help in this. Carbon dioxide captures some of this radiated heat and keeps it in the atmosphere. Some other greenhouse gases are water vapor, methane, nitrous oxide, and CFCs. In fact, any gas with three or more atoms acts as a greenhouse gas.

Other greenhouse gases:

Shortwave energy (that emitted by the sun) passes through the atmosphere pretty much unimpeded, ultimately to be intercepted by the ground. The warm ground emits longwave radiation in proportion to the fourth power of its temperature. In a completely dry, CO2-less and ozone-less atmosphere, this upwelling longwave radiation would all be lost to space. Carbon dioxide absorbs upwelling long wave radiation and re-emits it back to the ground, thereby reducing the amount of heat that escapes to space, warming the planet. The warmer planet evaporates more water, and the water vapor absorbs even more longwave radiation than the carbon dioxide, warming the planet even more.

Incoming solar radiation is widely distributed across the electromagnetic spectrum. Some wavelengths (mostly visible light) get through the atmosphere to the surface, some don't. Of the radiation that gets through, some is reflected and some is absorbed by the surface of the earth. The reflected radiation is not an issue, because it goes right back into space at the same wavelengths that it came in at, unimpeded, just like on the way in. It is only the absorbed radiation that is a problem. This radiation is later re-emitted, but in the form of Infrared Radiation (IR).

Certain atmospheric gases, known as "greenhouse gases", including carbon dioxide, 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.

Greenhouse gases 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 gases eventually finds its way back to the surface, with the remainder escaping into space.