Residence times of a given molecule in the 'reservoir', i.e. the atmosphere, is reservoir size divided by the total flux, or inputs or outputs of the reservoir (if input is equal to output). That's the simple answer. When the reservoir is changing it becomes more complex. Water vapor has a residence time of about 1 week. CO2 can be a few years to a couple hundred years, methane about 12 years, NOx, 114 years, CFCs, about 45 years, CF4, greater than 5000 years.
Though technically correct the paragraph above is a little simplistic. Current models indicate multiple residence times for CO2 in the atmosphere. For a pulse of additional CO2 about half is removed quickly, 5-15 yrs, 1/3 remains for ~100 yrs, and 1/5 for thousands of years. Not all sources and sinks respond the same way to an increase.
One has to be careful with the nomenclature here: IPCC refers to "lifetime" or "adjustment time", which refers to the time it takes for an excess amount of the gas in the atmosphere to decay to a fraction 1/e. This is not the same as the mathematical "residence time" (= average time for a trace gas molecule until it exits the atmosphere) or the "turnover time" (= amount of trace gas in the atmosphere divided by the total source or sink flux). For a well mixed reservoir such as the atmosphere, the residence time is equal to the turnover time. For a chemical compound with first order decay (e.g. CFCs) the residence time is also equal to the adjustment time. However, for CO2 it is different: the residence time is quite short - only a few years, while the lifetime or adjustment time is much longer, as described by Brian Brady above. The reason is that the CO2 sinks are not first order processes, but react to an increase in atmospheric CO2. E.g. ocean CO2 uptake increases the surface ocean partial pressure of CO2, which reduces further CO2 uptake. Therefore the multitude of time scales involved in the decay of a pulse CO2 input.
Sorry to say the IPCC has this wrong in AR4 and AR5 - which uses the Bern Model.
The Bern model has 4 bins and the reason they cannot give a simple straight answer to how long CO2 stays in the atmosphere, is because their model has 4 different lifetimes - 1 for each bin. The bin lifetimes vary from short term (a few years) to "forever" for about 15% of the CO2 in the air. This is an over-complicated answer to a simple question.
For a simple answer read Dr. Edwin Berry's recent paper which says the residence time (he calls it the e-time) is about 5 years.
Article Human CO 2 Emissions Have Little Effect on Atmospheric CO 2