I would like to know how gamma rays from cosmic rays are blocked by the earth's atmosphere. I know that the sun's gamma radiation don't usually reach the earth so I wouldn't be worrying much about it. I have did some research and I only see that ozone will block uv radiation but not gamma radiation. So I am wondering how is gamma radiation being blocked by the atmosphere? What molecules in the atmosphere specifically absorb gamma radiation? Thank you!
Cosmic gamma rays are largely absorbed in the atmosphere by three ionizing interactions with atmospheric molecules: photoelectric effect, Compton scattering and pair production. Therefore, in order to observe cosmic gamma rays for astronomical purposes, gamma ray observatories (like the Compton Gamma Ray Observatory) have to be placed in space.
Gammas lose energy predominantly via Compton scattering, $\gamma +e\to \gamma +e$, during which they impart much of their energy to the electron and change direction. Low-energy gammas, which you might better call x-rays, tend to induce bound-free transitions, $\gamma +atom\to e+ion$.