Earthquakes and volcanoes are intimately linked. They are both products of the plate tectonic process that is constantly reshaping the surface of the Earth. But even beyond that, earthquakes are some of the best clues we have that a volcano might be heading towards an eruption. So, why are there earthquakes in the days-months-years before a volcano erupts and why do some earthquakes lead to an eruption and some don't? Well, it is a little more complicated than it seems.
When we're talking about earthquakes that are leading up to an eruption, the key reason they occur is magma on the move. Most magma that is the source of volcanism in places like Iceland, the Cascades, Sicily and almost every volcano on the planet is initially formed by melting the mantle, many (8-80) kilometers beneath our feet. That magma is buoyant because it is hot, chock full of gases and made of less dense material than the rock around it, so it rises.
Although we tend to think about magma as a liquid, it is a very dense and viscous liquid compared to something like water. This means it can exert a lot of force on the rocks around it as it rises its way through the crust. This is what generates much of the earthquakes that occur in volcanically active areas: the fluid pressure from the rising magma cracking the rock, making space for itself as it rises.
The earthquakes causes by this don't tend to be large—rarely are they larger than magnitude 5 and usually they less than magnitude 3. You might be hard pressed to notice them at all if you were standing on the volcano itself. However, if magma is rising steadily, the location of the earthquakes in the crust will change. They will become shallower and they might even move laterally as the magma tries to find the easiest path out of the crust. By locating the earthquakes in the crust, volcanologists can map out the pathway and location of the magma as it rises. These earthquakes generated by magma cracking the rock along the way upwards are called volcano tectonic (VT) earthquakes.
You also get long-period (LP) earthquakes under volcanoes as bubbles form and escape from the magma during its ascent. Unlike VT earthquakes, LP earthquakes gradually begin and then fade away rather than being abrupt events. So, if a swarm of earthquakes under a volcano is a combination of VT and LP events, it is a pretty good sign that the earthquakes are being caused by magma moving into shallower parts of the volcano. However, as the magma gets closer to the surface, VT events tend to go down as LP events increase. They can also occur as hybrid (or mixed) earthquakes that have some of the VT and LP characteristics.
A third type of shaking can occur under volcanoes and that is harmonic tremor. This is small but constant shaking possibly caused by the turbulent motion of the magma in the conduit. Typically when volcanologists are watching a volcano that is restless, the onset of harmonic tremor is a good sign that an eruption is likely to occur in minutes to days.
These three types of earthquakes—VT, LP and harmonic tremors—are the clues that volcanologists use to determine if the volcano is heading towards an eruption (along with the suite of other volcano monitoring tools). All of these earthquakes can occur at a volcano that does not end up erupting, so putting all the clues together is vital for an accurate forecast. Volcanologists also use seismic information to look for eruption events like explosions and lahars (mudflows) as they can also produce their own, distinct earthquakes.
And if that wasn't tricky enough, earthquakes can occur under volcanoes that have nothing to do with magma. Places with abundant volcanoes also tend to be riddled with faults, so earthquake swarms that are merely tectonic are common. What volcanologists look for to determine if an earthquake is potentially related to magma movement or just fault motion is if the earthquake was caused by dilation (opening) of the crust (magma movement) or some other type of motion (tectonic).
Earthquakes can also be generated in the shallow crust (a few kilometers below the surface) by hot fluids in the volcano's hydrothermal fluids. All the water that percolates through the crust over volcanoes can heat up (sometimes to the point of becoming a supercritical fluid) and as those fluids move, the accompanying change in pressure can fracture the rocks around the fluid. If you look at places where geothermal energy is being tapped or at a restless caldera like Yellowstone, earthquake swarms are common from hydrothermal fluids.
If you watch webicorders that volcanologists have installed at many volcanoes, you can see the different types of earthquakes as they occur. However, seismometers like these also pick up earthquakes that happened all over the world or even non-geologic shaking like truck, people or wind. Although it is easy to watch these near-realtime records of volcanic shaking, it takes training to interpret all those blips into a forecast for a volcano.
So, earthquakes are a great tool for understanding what might be going on under a volcano, both during times that it might be heading towards an eruption or periods when all is quiet. The earthquake record at Mount St. Helens in Washington shows how even during times before and after eruptions (2002-2012), the earthquakes deep under the volcano don't stop—that's because magma is always moving, cooling, degassing and recharging with new magma. Calling a volcano "dormant" is a bit of a misnomer as the only part that is quiet is the top and really, volcanoes spend most of their life not erupting. Those earthquakes remind us that volcanoes are always rumbling.