Piston aircraft engines use magnetos: self-contained generators that make their own spark, so the engine keeps running if the electrical system fails. Each engine has two magnetos and two spark plugs in every cylinder, for safety and a faster, more even burn.
Inside a magneto
A rotating permanent magnet builds a field in a primary coil. Breaker points open at the right moment and the field collapses fast, and the secondary coil, with many more turns, turns that into the thousands of volts a spark plug needs. A condenser (capacitor) across the points stops them arcing and speeds up the collapse. The distributor sends each spark to the right cylinder. The points are timed to open at the E-gap, a few degrees past the magnet's neutral position, where the field is under the most stress.
Switching it off: the P-lead
The ignition switch turns a magneto off by grounding its primary circuit through the P-lead. If a P-lead breaks or comes loose, that magneto stays live with the switch off: a hot mag. Anyone turning the propeller could start the engine. Check with the mag check during run-up and a quick switch-off test as the manual describes.
Starting
Cranking is too slow for a good spark, so one magneto has an impulse coupling: a spring winds up and then flicks the magnet round quickly, and delays (retards) the spark to near top center so the engine doesn't kick back. It makes a clicking sound as you turn the propeller. Most piston engines use a direct-cranking electric starter; turbines use electric starter-generators or air turbine starters.
Timing and plugs
Magneto-to-engine timing sets the spark a given number of degrees before top center, from the engine's data plate or manual. Spark plugs are gapped with a round wire gauge, fitted with new gaskets, torqued to the manual's value, and rotated: top plugs to the bottom and swapped from side to side, to even out wear. Their heat range must match the engine.
Turbine igniters use a capacitor discharge exciter that stores lethal energy. Wait the time the manual gives after switching off before touching the leads.
Practice
Why do piston aircraft engines use magnetos?
More info
Quick reference
Magneto
Self-contained spark generator; two per engine.
P-lead
Grounds the magneto's primary to switch it off.
Hot mag
A magneto that's live with the switch off.
Impulse coupling
Fast, retarded spark for starting.
E-gap
Where the points open, just past the magnet's neutral position.