We know that some eruptions on the Sun can cause magnetic storms.
The eruptions on the Sun often send out light, radio waves, or X-rays, all of which travel to the Earth in about 8 minutes.
But electrically charged particles (that is, matter) from the Sun's eruptions are the actual cause of the magnetic storms, and they take many hours to a few days to reach Earth.
By using instruments to watch the Sun, the intervening space, and the Earth's magnetic field, scientists may be able to warn of magnetic storms on Earth.
But the theories that are currently used are far from perfect, and scientists around the world are working to make them better.
What data do we use in forecasting?
At many observing sites around the Earth and on several satellites, sophisticated instruments are watching the Sun.
Data from these instruments can tell us about the Sun's features such as active regions, coronal holes, and filaments, and about eruptions such as solar flares and coronal mass ejections (CME).
Data from the satellite ACE (Advanced Composition Explorer), which is about 1.5 million kilometres from Earth towards the Sun, tell us about the conditions in the solar wind, the streams of particles coming from the Sun.
Data from many magnetometer recording sites around the world tell us what the effects of the Sun on the Earth's magnetic field are.
By looking for patterns and clues in the data, scientists develop scientific theories from them. Using these theories and new up-to-date data, we can produce forecasts of how we expect the Earth's magnetic field will behave in the near future.