What is the math equation to calculate the difference between two different shutter speeds in stops?
It helps to start with exactly what a "stop" means. See What is one "stop"?, but, fundamentally, each stop is a doubling or halving of the exposure.
So, given two shutter durations, you can find the number of stops between them by calculating the binary logorithm (log₂) of each, and subtracting. (If you don't remember your elementary school math very clearly, logorithms may sound complicated, but are really just counting the number of times you multiply by the same number — in this case, two.)
In formula form, that is:
log₂(second duration) - log₂(first duration)
For example, we know that going from ¹⁄₃₀ to ¹⁄₆₀ is down one stop, trivially. But to work it out:
log₂(1÷60) - log₂(1÷30) ~ -5.9 - ~ -4.9 -1
Or for a more extreme example, from ¹⁄₁₀₀₀ to 30 seconds:
log₂(30) - log₂(0.001) ~ 4.9 - ~ -9.96 ~ 14.9
so, 15 stops. Note that it's incredibly important to not worry about excess precision. The standard scale of shutter speeds follows human-friendly numbers, not log₂, and the closest power of 2 may or may not be used internally. Overall in almost anything in photography, if it's less than a third of a stop, round it off.
If you don't have a calculator supporting log₂, you can calculate it in the following manner:
log₂(x) = log(x)/log(2)
where "log" is logarithm in any base (2, 10, or natural logarithm, or even something else). Very often, log10 or loge (in other words, ln, or the natural logarithm) are available when log₂ isn't.
If you don't have a calculator handy or don't want to figure out the precise log₂, you can simply start with one speed and double or halve in your head, counting the number of times it takes before you reach the other speed. (There is no shame in keeping track on your fingers as you go if you can't both calculate and count at the same time!)
This same formula works for ISO as well, by the way. It doesn't work for aperture as expressed in f/numbers, because those numbers are related to the diameter of the aperture but exposure is based on the area (see Why are f-stops not linear?). You can calculate log√2 if you have a fancy calculator handy, or you can double the result after plugging the aperture numbers into the formula (and then it will work).
In practice, though, shutter speed is the only one that where a formula might be handy, because few lenses have more than a 9-stop aperture range (and many much less), most cameras only have a useful ISO range of 6 stops (maybe a bit more these days) — but with bulb mode the range for shutter speed is almost infinite. Still, exponential scales collapse quickly — the difference between ¹⁄₈₀₀₀s and one hour is only about 25 stops, and the difference between a one hour exposure and a one year exposure only 13!
For the standard set of shutter speeds (1 sec, 1/2, 1/4, 1/8, 1/15, 1/30, 1/60, 1/125, 1/250, 1/500, 1/1000), divide the higher shutter speed by the lower, and round to 0 decimal places if necessary.
If the result is 2, it's 1 stop.
If it's 4, two stops.
If it's 8, three stops.
If it's 16, 4 stops. See the pattern?
If the shutter speed falls between the ones I gave, drop down to the shutter speed that's just longer than one of the ones I gave. Do the above calculation and then subtract half a stop.