Which layer of the Earth is responsible for the Earth's magnetic field?

The Earth's magnetic field is the result of electric currents in the liquid metal outer core.

The outer core of the Earth is over 2,000 km thick. It sits above the solid inner core and is composed of highly conducting liquid iron and nickel. Above the outer core is the Earth's mantle.

The geodynamo is the mechanism thought to be responsible for the electric current in the core and the generation of the Earth's magnetic field through the convection of conducting fluids in the Earth's core. Other planets with a molten metal core can also have a magnetic field.

See related links.