Planetary magnetic fields are generated by dynamo mechanisms: convection of electrically conducting liquid iron in planetary cores induces electric currents that produce self-sustaining magnetic fields. Field strength scales with core temperature contrast, rotation rate, and electrical conductivity.
Compare Earth's active dynamo with Mars' extinct field (lost after core cooling) and gas giants' strong fields (driven by internal convection). Examine how rotation rate affects field morphology.
From your study of planetary interiors, you know that terrestrial planets have layered structures with iron-rich cores, and that convection moves heat through these interiors. From your introduction to magnetic fields, you know that moving electric charges produce magnetic fields. A planetary dynamo connects these two ideas: when electrically conducting liquid iron in a planet's outer core convects vigorously, the fluid motion generates electric currents, and those currents produce a magnetic field that sustains itself through a feedback loop.
The feedback works like this. Start with a weak "seed" magnetic field — even a tiny one left over from the planet's formation. As conducting liquid iron flows through this field, the motion induces electric currents (by electromagnetic induction, the same principle behind a generator). Those currents produce their own magnetic field, which reinforces the original seed. The reinforced field then induces stronger currents in the moving fluid, which produce an even stronger field. This self-exciting dynamo can sustain a planetary-scale magnetic field for billions of years, as long as the core keeps convecting. The energy source is not magnetism itself — it is the thermal and compositional buoyancy that drives convection. The magnetic field is a byproduct of that convection happening in an electrically conducting fluid.
Three ingredients determine whether a planet has an active dynamo: a conducting fluid (liquid iron or, in gas giants, metallic hydrogen), convective motion in that fluid (driven by heat escaping from the core or by light elements rising as the inner core solidifies), and planetary rotation (which organizes the convective flows into columnar structures through the Coriolis effect, making the dynamo more efficient). Remove any one of these and the dynamo fails. Mars, for example, once had a magnetic field but lost it when its small core cooled enough to stop convecting — the conducting fluid solidified or became too viscous to flow. Mercury retains a weak field because a portion of its large iron core remains liquid. Jupiter and Saturn have enormously strong fields because metallic hydrogen in their deep interiors convects vigorously under rapid rotation.
A common misconception is that bigger cores mean stronger fields. In reality, what matters is the vigor of convection and the rate of rotation, not size alone. Earth's field is far stronger than Mercury's despite Mercury having a proportionally larger core, because Earth's core convects more actively. Similarly, magnetic poles are not fixed landmarks — they wander as convective patterns in the outer core shift over time, and the field can even reverse polarity entirely, as Earth's has done hundreds of times in its geological history.