No one is actually sure. Along time ago a calculation was done assuming the earth is a perfect black body (which it isnt), this gave an average temperature of -18. Since the earth has an average temperature of around 15 degrees it was assumed that there was a greenhouse effect that added 33 degrees of warming.
The hypothesis has a number of issues, as firstly the earth isnt a black body, a grey body calculation is more representative. The moon is more of a black body, but the moons temperatures do not match the calculation either without an atmosphere (I assume this is due to warming of the surface in the day and release of the heat at night).
No calculation ever took into account the effect of the sea which can absorb, store and release energy far more effectively than ground which I see as a major oversight.
The hypothesis is that watervapour and some other trace gasses (i.e. 0.054% co2) allow incoming high energy solar energy through but then cause emission by absorbing infrared energy emitted by the earth towards space and than re-emits part of it downwards towards the earth were it heats the surface. This contradicts the second law of thermodynamics but is none the less widely accepted as a real effect. When questioned how energy is re-emitted to the earths surface within the laws of physics it is explained as being to complex to explain!
This is known as the Arrhenius hypothesis which was not
verified (Arrhenius 1896), it has never been shown to be correct either practically or theoretically (it has been falsified practically and theoretically though) and hence is a unproven hypothesis - yet in current climate science it was assumed to be correct without any critique, yet it forms the basis of the entirement global warming argument!
Some scientists have recently proposed the "greenhouse effect" hypothesis is incorrect and is infact a function of atmospheric mass as this can be explained within the laws of physics, but this better hypothesis has failed to be widely accepted for earth, though it has been for other planets.
The greenhouse effect is often shown as a layer over the earth in the sky, but it is infact at your feet where atmospheric mass is greatest and the most watervapour is found i.e. the air there can hold the most warmth. Air temperatures constantly decrease will altitude in accordance with the atmospheric mass hypothesis, hence there is no layer "trapping heat" as is often incorrectly shown diagrams.
The effect in an actual greenhouse that causes warming is the lack of convection. It used to be thought that is was caused by radiative forcing i.e. the energy was trapped by the glasses infrared absorbing ability and it warmed until a equilibrium point was reached. This was well disproven many years ago, but the greenhouse effect is still believed to function this way and scientific literature still often compares the two. The real question is why is it colder outside of the greenhouse when there is the same incoming energy?
Practical tests using polished rock salt and infrared absorbing glass that mimics co2 shows no warming effect with co2 (actually the co2 mimicking glass causes slight cooling). Tests with chambers containing elevated co2 show no warming effect either, even at very high concentrations so the hypothesis fails testing.
A physicists published a paper on the greenhouse effect a couple years ago, he concluded it was not possible within the laws of physics. There was a rebuttal but it did not question the fact that the greenhouse effect is in breach of the second law of thermal dynamics i.e. its a perpetuem mobile of the 2nd kind, i.e. an impossible heat pump that doesnt require work to drive it.