The most common volcanic gases are carbon dioxide, water, sulphur dioxide and hydrogen sulphide - these giving the distinctive odour associated with volcanic activity. Small quantities of other volatile elements and compounds are also present such as hydrogen, helium, nitrogen, hydrogen chloride, hydrogen fluoride and mercury. Some volcanic gases are less soluble in magma than others and will separate out at higher pressure. As magma ascends from deep inside the earth, the pressure acting on it decreases and allows the various gases to 'bubble' out. Studies at Kilauea Volcano in Hawaii suggest that carbon dioxide begins to separate from its parent magma at depths of about 40 kilometres, whereas most of the sulphur gases and water are not released until the magma has reached nearly to the surface.
Carbon dioxide is the least soluble and so is the first to separate.
It is the expansion and joining up of these gas bubbles which tears the magma up into lumps or clots which form the pumice and ejected material in explosive eruptions. This depends on where the magma was formed in the earth. The magma in basalt volcanoes, such as those in Iceland or Hawaii, has its source in the mantle, the layer directly beneath the surface 'crust' of the earth, and so any gas here comes mainly from gas locked into the melted minerals. If volcanic rocks erupt on the earth's crust, such as the Andean volcanoes, then magma can interact with carbonate rocks such as chalk as it travels up through the mantle or lower crust, picking up carbon dioxide on the way. In subduction zones, where the ocean floor goes down into the mantle some carbonate rocks do get taken down and melted, recycling their carbon dioxide content, but this is a minor source compared with the mantle.