How are they created?
Magnetic fields are caused by the movement of charge, it can be caused by electrons moving in a wire (Temporary Magnet) , or electrons in atoms moving around in their orbitals (Permanent Magnet). The Earth has a magnetic field due to the currents carried by the molten iron in the core.
You can map magnetic field patterns around current carrying wires or permanent magnets using magnetic field lines. The Field lines are repelled from the north and attracted to the south and the more lines there are the greater the magnetic field.
In most atoms electrons are permanently moving within their orbitals creating a magnetic field but most molecules don’t have a magnetic field. This is due to the fact that magnetic fields can effectively cancel each other out, it is only when there is an imbalance in the magnetic fields that there is a ‘net’ magnetic field, due to certain properties of molecules/atoms some molecules are more likely to have a magnetic field than other.
Temporary/Electromagnets can be created by an electrical current moving through a wire, a magnetic field will be created around the wire in a circular shape as the magnetic field occurs perpendicular to the direction of the current. The direction of the magnetic field can be determined by the right hand grip rule.
Currents and magnetic fields come in a pair so you can’t have one without the other, this means that magnetic fields can be used to create a current. Generators use this fact to induce a current in a wire by moving it around in a magnetic field, the main way of doing this is rotating a coil of wire between two magnets of opposite polarity. This converts mechanical energy into electrical energy, as the direction of the current will alternate every half turn the output will be AC (Alternating Current).