Earthquake Hazards: Aftershocks
Every earthquake has aftershocks, which are essentially earthquakes of lesser intensity than the original mainshock.
Although they could technically be argued as separate earthquakes with their own related hazards, aftershocks are a hazard. The main earthquake may not have been expected, but you can expect these additional quakes and you should be wary around any damaged structure or building that has not be identified as safe.
The biggest aftershocks generally occur within the following 30 days, with the intensity of the aftershocks decreasing over time.
Think of it this way, these are earthquakes you can actually expect, and, to some extent, plan for, even if you don't know the exact day or time when they will strike.
More about Aftershocks and Foreshocks and Aftershocks on this page
Aftershocks - mathematical formula
I won't pretend to understand the mathematics behind aftershock prediction and modeling, but here's a oversimplification of the idea.
When you through a pebble into a body of water, the first wave it creates is the largest. But it's not the only wave. Multiple ripples are created from the energy release of the single pebble. These ripples continue to decrease until there's basically nothing left.
When predicting aftershocks, the magnitude of the mainshock is used. Over a period of time following the mainshock the theory is a certain amount of energy will be released in aftershock earthquakes.
Using mathematical formulas to estimate probabilities and timing, scientists can predict aftershocks to fall within certain magnitude ranges within certain time frames. For example, following a magnitude 7.0 earthquake the aftershock models may predict three aftershocks of magnitude 6.0 or larger during the next 30 days, along with 13 aftershocks greater than 5.0, and 77 aftershocks that are 4.0 or higher.
Over time the number of aftershocks and their intensities will continue to decrease. That said, an aftershock following a particularly large earthquake can happen years after the main shock. For most people it would be seen as another earthquake because of the amount of time that has passed since the mainshock. But for seismologists, the quake may be within the fault zone and aftershock model predictions to become classified as an aftershock.
In any case, all of these are earthquakes and can create the same hazards. The biggest issue with aftershocks are in the days and weeks following the original mainshock, when buildings and infrastructure are still damaged and many structures haven't been checked for safety.
If you want to dive into the actual mathematical formulas, go to the USGS page Aftershock Forecast Scientific Background