Smelting is a form of extractive metallurgy; its main use is to produce a metal from its ore. This includes production of silver, iron, copper and other base metals from their ores. Smelting uses heat and a chemical reducing agent to decompose the ore, driving off other elements as gasses or slag and leaving just the metal behind. The reducing agent is commonly a source of carbon such as coke, or in earlier times charcoal. The carbon (or carbon monoxide derived from it) removes oxygen from the ore, leaving behind elemental metal. The carbon is thus oxidized in two stages, producing first carbon monoxide and then carbon dioxide. As most ores are impure, it is often necessary to use flux, such as limestone, to remove the accompanying rock gangue as slag.