Fusion needs plasma at over 100 million degrees. No material container survives that, so the plasma is held in a magnetic field instead. Charged particles spiral along magnetic field lines and cannot easily cross them, which suggests an obvious design: bend the field into a closed loop so the particles run in circles forever.
The doughnut fails
In a ring-shaped magnet, the field is stronger on the inside of the ring than the outside, because the coils are packed closer together there. That gradient causes positive and negative particles to drift in opposite directions — up for one, down for the other. Charge separates, an electric field builds across the plasma, and the whole column is pushed straight into the wall.
The fix is a twist
Add a second field component that runs the short way around the tube, and the field lines become helical. A particle now spends part of its journey near the top of the cross-section and part near the bottom, so the two drifts cancel over a full circuit instead of accumulating.
A tokamak generates that twist by driving an enormous current through the plasma itself, using the plasma as the secondary winding of a transformer. A stellarator builds the twist into the geometry of the external coils instead, which is why its magnets look like they have been crumpled by hand.
The trade
The tokamak is simpler to build but the driving current is naturally pulsed and can go unstable, ending in a disruption. The stellarator runs continuously and steadily, but its coils have to be shaped and positioned to tolerances that only became practical with modern computation and manufacturing.

