In the upper atmosphere, O2 dissociates to give 2 oxygen atoms. In such a way many oxygen atoms are formed. An oxygen atom is unstable. So when any 3 oxygen atom combine, it results in the formation of a ozone (O3) molecule. The process goes on and this leads to the formation of ozone layer in the upper atmosphere. This layer protects us from harmful UV rays of the sun.