Magnetic fields in certain materials (most commonly metals) are created due to moving electrons within these materials, which create an electric current.The distribution of electrons in these metals is uneven, resulting in an irregular rotation and lots of movement that then creates two magnetic poles (a north and south pole). When these poles align and face the same direction, they create a magnetic field.