Question: why earth has magnetic field?
Answer: The magnetic field of Earth is caused by currents of electricity that flow in the molten core. These currents are hundreds of miles wide and flow at thousands of miles per hour as the earth rotates. The powerful magnetic field passes out through the core of the earth, passes through the crust and enters space.