Some metals are extracted from their ores by heating with carbon, but this only works for metals less reactive than carbon. If a metal is too reactive, or if it reacts with carbon, it must be extracted by electrolysis of a molten compound. Aluminium is made this way.
Aluminium oxide has a very high melting point, so melting it alone would use huge amounts of energy. Instead it is dissolved in molten cryolite. This mixture is used as the electrolyte because it melts at a much lower temperature, which saves energy and cost. Aluminium forms at the cathode and the molten metal collects at the bottom of the cell.
The anodes are made of carbon. Oxygen is produced at the anode, and at the high temperature it reacts with the carbon to make carbon dioxide gas. The carbon anodes slowly burn away, so the positive electrode must be continually replaced. Extraction by electrolysis is expensive because a lot of energy is needed to melt the compounds and to produce the electric current.