how the ozone layer is formed
These oxygen atoms are called free radicals. ie they have at least one unpaired electron. Because of this, free radicals are very reactive. An oxygen atom will then react with an O2 (oxygen) molecule to form ozone.
Additonally, there are biological pathways where ATP can generate ozone (the roots of marigolds produce it when attacked by predators).
Ozone production in general:
Ozone in the ozone layer is formed when UV-C from the Sun dissociates an oxygen molecule, and some of those now-loose oxygen molecules connect with an oxygen molecule to form ozone.
Ozone in a rain storm is made by lightning dissociating oxygen molecules, and the rest occurs as above.
Ozone in tropospheric ozone pollution is directly made by internal combustion engines, but mostly by photoproduction when NOx (from combustion exhaust), and VOC (unburned fuel and "cow farts") are converted by violet or more energetic light into ozone and nitrogen gas (and the VOC just moves on).
Ozone in medical / industry / water treatment is made either by UV lamps (for low concentrations) or by electrical discharge dissociating oxygen molecules, and the rest occurs as above.
Ozone in the bloodstream is made by white blood cells (along with other powerful oxidants) in very tiny areas, when fighting infection at a site. The resultant of this fight is called "inflammation" or "swelling".
In the upper atmosphere: Light from the Sun breaks apart oxygen molecules (UV wavelengths of 215nm or shorter). Some of this monatomic oxygen combines with nitrogen molecules, some with oxygen molecules to make ozone, but most with other monatomic oxygen. Some of the nitrogen+oxygen molecules can catch lower energy light (still UV, but more available) and make ozone also. As the density of the atmosphere increases, this happens more and more often, until there is little / no UV-C available to break apart more oxygen molecules.
"Running out of UV-C" happens in the upper atmsophere. This is the bottom of the stratosphere / top of the troposphere, where ozone is at its peak concentration... the 'ozone layer". The atmosphere increases with density as the light comes from higher elevation, and eventually, all the UV-C has been absorbed. So ozone increases with decreasing elevation until it gets to the bottom of the stratosphere (where the ozone layer is located), where its concentration falls off pretty sharply with further decreases in altitude.
Scavengers of ozone are water vapor (decays ozone making hydrogen peroxide, blocks the nitrogen+oxygen path of ozone formation), any compound / process that consumes oxygen, and catalysts (such as some chlorine compounds) that convert ozone back to oxygen. Absorption of UV-C or UV-B by ozone, also breaks apart the ozone molecule (only some of which reforms as ozone later).
So the concentration of ozone at any given point is a balance of ozone production, ozone diffusion from adjacent areas, and ozone decay from just time and contaminants from other sources (both natural and Man-caused).