Sunscreen works by preventing the penetration of UV radiation into the skin. UV radiation, particularly UVB and UVA rays, can damage the DNA in skin cells, leading to mutations that may cause skin cancer. By blocking or absorbing these rays, sunscreen reduces the risk of developing skin cancers such as melanoma, basal cell carcinoma, and squamous cell carcinoma.