Ozone in ozone layer If ozone is a gas, and gases have the highest entropy, then how does the ozone gas stay within a few layers of the atmosphere, even though they span for kilometers?
It does not have much to do with entropy, rather with the way and place of ozone creation.

Stratospheric ozone is produced typically at altitude 20-30 km by UVC radiation with $\lambda \lt \pu{280 nm}$:

$$\ce{O2 + \nu -&gt; 2 O}$$
$$\ce{O + O2 -&gt; O3}$$

See ozone cycle as courtesy of @M. Farooq.

Ozone in lower troposphere troposphere is created by UVB (280-320 nm)  (+UVA >320 nm ??) mostly due catalytic effects of nitrogen oxides that come typically of the oxidative smog of the Los Angeles type:

$$\ce{NO2 + \nu -&gt; NO2^{*}}$$
$$\ce{NO2^{*} + O2  -&gt; NO + O3}$$
$$\ce{2 NO + O2 -&gt; 2 NO2}$$