It is important to note that the field lines are all loops. Magnetic fields have no beginning or end. The field lines close to form loops within the magnet. Pocket Galvanometer Moving charges produce a magnetic field. This is shown by wrapping wires around a compass and connecting the wire across a battery.
All magnetic fields arise from the motion of charges.
In a permanent magnet the magnetic field is produced by the motions of electrons in the atoms of the magnet. Electromagnet Wire looped around a nail makes a magnet when the wire is connected across a battery. If the connection is switched in direction the magnetic field produced by the wire switches direction. The strongest magnets we have are made in this way. Student volunteers are challenged to pull apart a powerful electromagnet powered by a single flashlight battery.