The smell is probably ozone, which typically has a sweet, pungent aroma. In stormy weather, lightning splits atmospheric nitrogen and oxygen molecules. These can then combine into nitric oxide, which, with further reactions, forms ozone. This is then carried downwind ahead of the rain with its characteristic fresh scent.
Closer by, there is a deliciously earthy smell that is associated with light rain following a prolonged dry period. This is due to a combination of compounds in the soil that are produced by plants and bacteria.
In long, dry stretches, plants produce a growth-inhibiting fatty acid that was given the name petrichor in the 1960s, derived from petra, the Greek word for “rock”, and ichor, the golden blood of gods in Greek mythology. This aromatic compound is released from the soil and is the source of the earthy smell following rain.
Another part of the scent comes from the actinomycete bacteria that are often found in soil. In dry periods, they form spores and, in doing so, produce a molecule called geosmin (derived from the Greek words for “earth” and “smell”). It is said to be detectable by humans in concentrations as low as 5 parts per trillion.
The mechanism for the release of these chemicals into the air was only described as recently as 2015, when it was observed that bubbles of air that are trapped under a raindrop landing on a porous surface collect the spores and oils, then transport them up through the raindrop, releasing them into the air as aerosols.
The smell is most intense during light rain with little wind. If the rain is too heavy, the aerosols are washed out of the air and the smell is lost.
My father, an airline pilot in Australia in the 1940s, once spotted an enormous population of birds in Lake Eyre, South Australia. The area is completely dry and barren for most of the year but unseasonal rains had covered the region like an inland sea. He marvelled at how the birds could have known to travel there from hundreds of kilometres away. I now wonder if the same chemical signals that humans appreciate also attract birds and other wildlife that associate the scent with food and survival.