A tokamak confines high-temperature fusion plasma inside a torus using a strong toroidal magnetic field combined with a poloidal magnetic field generated by an internal plasma current. The resulting helical magnetic field lines trace out nested toroidal magnetic flux surfaces. The safety factor q(r) measures the number of toroidal transits per poloidal transit, preventing destructive kink and tearing MHD instabilities.