Why is there an ozone layer?

Ozone formation is a natural chemical process. When oxygen is treated with UV radiations oxygen gets converted into ozone. Oxygen in earth's atmosphere when exposed to sun's radiations got converted into ozone.