This is a great question, without the
magnetic field Earth could not support life as
we know it. We would have no ocean or air to
breathe. More on that later but first on the how
the core produces a magnetic field.

Geologist hypothesize that the core of Earth
is composed of a solid iron core and liquid iron
outer core. Now two things are important about
the cores's composition that makes it magnetic:
1. it is composed of iron and 2. it has a liquid
outer core. As you likely know iron is a
magnetic element. From physics we know a
magnetic field can be induced when a charged ion
moves in space. Think of it like electricity the
power lines have flowing electrons in them as
they move from the power plant to your home they
actually induce a magnetic field in the power
line.

Now for Earth's liquid iron outer core, it is
so hot the iron exists in a liquid, ionically
charged state. So when the charged liquid iron
moves about in the outer core the material
induces Earth's magnetic field.

Earth's magnetic field allows all life to
exist as we know it today. Without our magnetic
field Earth would be much like Mars, the
magnetic field extends into outer space beyond
our atmosphere and deflects high energy
particles emitted by the sun. If these high-
energy particles were not deflected they would
strip Earth's atmosphere, all the oceans would
evaporate into space, it would get very cold
below freezing, and destroy all life as we know
it.

Answer 2:

The Earth’s outer core is made of a mixture
of elements. The three main constituents are
iron 85% Nickel 10% and probably Sulfur 5%.

Because the Earth’s outer core is liquid, and
because it is electrically conducting, the
natural response of a moving conducting fluid is
to set up a magnetic field; this is called
Faraday’s law and was studied by JC Maxwell in
the late 1800s and early 1900's.

Answer 3:

As you acknowledge in your second question,
iron makes the earth's core so magnetic. I
think we know that it is iron that makes the
earth's core so magnetic, because we know how
big the earth is, and we know how fast the earth
rotates, so we can probably calculate how heavy
the earth is.

Then, we know how strong the magnetism is in
different materials, so we can calculate how
much of each material would be needed to make a
planet that is as big and heavy and magnetic as
earth.

Does that make sense?
Keep asking questions!

Best wishes,

Answer 4:

Good question!
Short answer: nobody knows.

Long answer: It has something to do with the
fact that molten iron, which is much of what the
core is made of, is capable of being magnetic,
and because there are currents that flow through
the molten core. Nobody really knows what the
directions and strengths of these currents are,
as well as other things that might matter, such
as how much nickel and other stuff there is in
the core as well. I am not enough of a
geochemist or a physicist to tell you what the
latest theories are, however, but I can tell you
that this is an area of active research.