Why does it smell like rain?
Petrichor is real, it has a chemistry, and your nose is absurdly good at it. Here is what you are smelling, before, during and after the rain.

The smell of rain is not one smell but three, and they arrive in order. Before the storm you may smell ozone, sharp and slightly metallic. As the first drops hit dry ground you smell petrichor, the earthy scent that two Australian scientists named in 1964. Underneath both is geosmin, a compound made by soil bacteria that the human nose can detect at about five parts per trillion. Together they explain why "it smells like rain" is often true minutes before the rain arrives.
Petrichor: oil from plants, released by raindrops
In 1964 Isabel Bear and Richard Thomas of Australia's CSIRO published a paper in Nature on what they called the "argillaceous odour" of dry clay and rock after rain. They coined the word petrichor from the Greek petra (stone) and ichor (the fluid in the veins of the gods). Their finding: during dry spells, plants release oils that settle onto soil and rock. Rain releases those oils into the air, along with the bacterial compounds that live in the same soil.
How the smell gets airborne was only filmed in 2015. Researchers at MIT used high-speed cameras to watch raindrops land on porous surfaces. Each drop traps tiny air bubbles at the point of impact; the bubbles rise through the drop and burst at the top, throwing a fizz of microscopic aerosols into the air, carrying the oils and bacteria with them. Light to moderate rain on dry ground produces the most aerosol; heavy rain produces less, which is why a summer shower after a dry spell smells stronger than a winter downpour.
Geosmin: the compound your nose was built for
The dominant note in petrichor is geosmin, a molecule produced by Streptomyces bacteria in the soil. Geosmin is the same compound that makes beetroot taste earthy and gives some tap water a musty note. Humans detect it at roughly 5 parts per trillion, which is among the lowest detection thresholds for any smell we know; a few drops in an Olympic pool would be enough. The leading explanation is evolutionary: for animals that need water, a nose tuned to "wet soil" is a nose tuned to survival. Camels are thought to find desert oases the same way, and the bacteria appear to benefit too, since insects attracted by geosmin carry their spores.
Ozone: the smell before the storm
The sharp, clean smell that sometimes comes before a thunderstorm is ozone, a three-atom form of oxygen. Lightning and the electrical charge inside storm clouds split oxygen molecules, some of which recombine as ozone. Downdraughts ahead of the storm carry it from height to your nose. Ozone can travel ahead of the rain by several miles, so smelling it is a genuine, if imperfect, early warning. If you also hear thunder, count the seconds to the flash before deciding whether to move indoors.
Why it smells stronger after a dry spell
Three things line up after weeks without rain. The plant oils have had time to accumulate on surfaces. The soil bacteria have been producing geosmin into dry ground where nothing washes it away. And dry, warm soil is more porous, so the first drops trap more air and throw up more aerosol. That is why the first rain of a drought-breaking front is the most fragrant, and why the smell fades within an hour or two even if the rain continues: the surface has been rinsed.
What the smell tells you about the forecast
Not much about tomorrow, but something about the next hour. Petrichor means rain is falling somewhere upwind within a few kilometres, carried to you on the wind. Ozone means an electrically active storm is near. If you want to know whether the rain reaches you, the rain radar answers it in one look, and the model comparison on any city page tells you how confident the forecast is for the rest of the day.