Within the Earth there is a large amount of iron which slowly moves, that movement creates a magnetic field around the Earth, that field bulges around the area of the equator and curves down towards the pole, this means that a free turning magnet will align itself with this field and point towards the north until you get close to the north pole. Occasionally this movement can change direction meaning that the North pole eventually becomes the South pole. https://youtu.be/QGTPr3CG6GA
Latest Answers