How do blankets keep you warm?
It may be worth pointing out that blankets also (surprisingly) act as (thermal) radiation shields. This is the reason that "emergency blankets" can sometimes be found in survival kits that appear to be nothing more than thin shiny plastic. But they really make a difference in the amount of heat lost by a warm (37 °C) body on a cold night (cloudless sky - assume 0 °C).
For a body with an area of 30 cm x 180 cm facing the sky, the area is roughly $0.5 m^2$. Assuming an emissivity of 0.3 (just picking a number), the heat loss is given by
$$E = \epsilon \sigma (T_1^4-T_0^4) = 53 W/m^2$$
Or 25 W for the human I just mentioned. That is a not insignificant amount of heat... especially when you consider that the basal metabolic rate ("doing nothing" which is a good approximation of sleep) is around 60 W. And that's not counting the heat you will lose by breathing (heating cold air, and filling it with vapor).
Heating cold air (still going with 0 °C as our baseline):
250 ml per second, heat capacity 1020 J/kg/C, $\Delta T = 37 C$, you get about 12 J
Evaporating water:
Saturated vapor pressure of water at 37 °C around 47 mm Hg, and breathing about 250 ml per second (900 liter per hour) with an effective fraction of 47/760 per volume of water, this takes another 25 W.
So surprisingly, these three mechanisms result in similar amounts of heat loss - and protecting yourself from radiative heat losses is indeed significant. Because of this, a good blanket (which will reflect some of that heat back to you) is indeed "keeping heat in".
The above underlines that the most significant form of heat loss is evaporation. A good blanket stops circulation, and will keep the air near your body "moist". This will slow down the rate of evaporation, helping you stay warm. Stopping the air from circulating also stops it from carrying away "heat" - but the amount of heat carried by moist air is significantly greater than "just air", as the above example demonstrates.
There is more to this question than meets the casual eye...
The thermal conductivities of a range of materials is given here. I can't find figures for the thermal conductivity of solid wool or cotton (i.e. a solid block with no air voids in) but the thermal conductivities of organic materials seem to be around $0.25$ Wm$^{-1}$K$^{-1}$. By contrast the thermal conductivity of air is $0.024$ Wm$^{-1}$K$^{-1}$, so given a constant body temperature and external temperature you would lose ten times less heat when insulated by air than when insulated by most solid materials.
The trouble is that air won't stay in a static layer surrounding your body. Air currents and thermal convection created by the heat of your body cause the air to move. This will replace the warm air that you've heated to your body temperature with cold air, and increase the rate of heat loss.
Ideally what you want is some stuff that can hold air in place around you so the air can't move and carry heat away. And you want this stuff to be as insulating as possible. The best such material I know of is silica aerogel, which is such a good insulator it was used on the space shuttle as a heat shield for re-entry. Glass is actually a rather poor insulator, but aerogel contains only a few percent glass by volume and the other 90 odd percent of its volume is air. Hence it's excellent insulating properties. However aerogel is a brittle solid and a poor choice for bedclothes.
Blankets are something of a compromise. They contain a lower percent of air by volume than aerogel, and they also trap the air less tightly, and both factors lower the insulating properties. However they're a lot more comfortable than aerogel would be.