"Foreshock" and "aftershock" are relative terms.
Foreshocks are earthquakes that precede larger earthquakes in the same location. An earthquake cannot be identified as a foreshock until after a larger earthquake in the same area occurs.
Aftershocks are smaller earthquakes that occur in the same general area during the days to years following a larger event or "mainshock." They occur within 1-2 fault lengths away and during the period of time before the background seismicity level has resumed. As a general rule, aftershocks represent minor readjustments along the portion of a fault that slipped at the time of the mainshock. The frequency of these aftershocks decreases with time. Historically, deep earthquakes (>30 km) are much less likely to be followed by aftershocks than shallow earthquakes.