Rossby waves arise due to the conservation of absolute vorticity and they are well known in the Earth's atmosphere. However, inclusion of horizontal magnetic field splits the ordinary hydrodynamic Rossby waves into fast and slow magnetic Rossby modes. We show that the magnetic Rossby waves in the solar tachocline are responsible for the variation of solar activity over two different time scales: much shorter and much longer than the solar cycle. Observed short period oscillations in the solar activity (155-160 days so called Rieger periodicity) is explained by fast magnetic Rossby waves, while observed long-period modulation of the solar activity (over hundreds and thousands of years ) is explained by slow magnetic Rossby waves. Based on magnetic Rossby wave theory, we can predict the future solar activity. According to our model, the next deep minimum in solar activity is expected during the first half of this century.