Smelting is a form of extractive metallurgy; its main use is to produce a metal from its ore. This includes iron extraction (for the production of steel) from iron ore, and copper extraction and other base metals from their ores. Smelting uses heat and a chemical reducing agent to change the oxidation state of the metal ore; 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 to leave the 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.