A magnitude 8.7 earthquake is 794 times BIGGER on a seismogram than a magnitude 5.8 earthquake. The magnitude scale is logarithmic, so

(10**8.7)/(10**5.8) = (5.01*10**8)/(6.31*10**5) = .794*10**3 = 794 OR = 10**(8.7-5.8) = 10**2.9 = 794.328

Another way to get about the same answer without using a calculator is that since 1 unit of magnitude is 10 times the amplitude on a seismogram and 0.1 unit of magnitude is about 1.3 times the amplitude, we can get,

10 * 10 * 10 / 1.3 = 769 times [not exact, but a decent approximation]

The magnitude scale is really comparing amplitudes of waves on a seismogram, not the STRENGTH (energy) of the quakes. So, a magnitude 8.7 is 794 times bigger than a 5.8 quake as measured on seismograms, but the 8.7 quake is about 23,000 times STRONGER than the 5.8! Since it is really the energy or strength that knocks down buildings, this is really the more important comparison. This means that it would take about 23,000 quakes of magnitude 5.8 to equal the energy released by one magnitude 8.7 event. Here's how we get that number:

One whole unit of magnitude represents approximately 32 times (actually 10**1.5 times) the energy, based on a long-standing empirical formula that says log(E) is proportional to 1.5M, where E is energy and M is magnitude. This means that a change of 0.1 in magnitude is about 1.4 times the energy release. Therefore, using the shortcut shown earlier for the amplitude calculation, the energy is,

32 * 32 * 32 / 1.4 = 23,405 or about 23,000

The actual formula would be:

((10**1.5)**8.7)/((10**1.5)**5.8) = 10**(1.5*(8.7-5.8)) = 10**(1.5*2.9) = 22,387

This explains why big quakes are so much more devastating than small ones. The amplitude ("size") differences are big enough, but the energy ("strength") differences are huge. The amplitude numbers are neater and a little easier to explain, which is why those are used more often in publications. But it's the energy that does the damage.