The magnetic field that causes sunspots is generated by the Sun's rotation. As the Sun rotates, the plasma inside it is dragged along by the magnetic field lines, which become wound up and twisted. This creates strong current sheets, which can then break and release their energy in the form of solar flares and coronal mass ejections.
Sunspots often occur in pairs or groups, and their size and number vary over time. The largest sunspots can be as wide as the Earth, and they can last for several weeks or even months. Sunspots are more common during periods of high solar activity, and they tend to be more numerous during the Sun's 11-year activity cycle.
Sunspots have been studied for centuries, and they are now known to be a natural part of the Sun's activity cycle. They are a source of energy for the Sun's atmosphere, and they can affect the Earth's weather and climate.