Sun radiates different types of light. Some of it falls into the so called ultraviolet range (UV light). When you hear terms "sun protection" and "sunscreen", what is usually meant is protection from the UV light.
The effect of light on the skin depends on the length of its wave. The shorter the wave, the more energy it has, but also, the more "shallow" it is in terms of how deep it can penetrate into our skin. The longer the wave, the less powerful it is in terms of energy, but the deeper it can penetrate into the skin.
Depending on the wavelength, we differentiate ultraviolet light type A (UVA), ultraviolet light type B (UVB), and ultraviolet light type C (UVC). UVC rays are the shortest, most powerful, and least penetrating, while the UVA rays are the least powerful, but the most penetrating among the three types. Luckily, the ozone layer in the atmosphere absorbs the UVC rays so they don't reach the Earth surface and don't get a chance to harm our skin.
UVB and UVA rays, however, make it through. UVB rays, as their wavelength is short and energy is high cause an immediate damage to our skin causing a sunburn and a direct DNA damage in our epidermis (the top layer of our skin). This damage can lead to skin cancers and aging.
UVA rays are longer and less powerful, so they do not cause an immediate visible energy. You don't get a sunburn from the UVA rays. However, because their waves are longer, they can penetrate deeper into the skin, damaging the dermis - the skin layer with collagen and elastin fibers. This is why UVA rays are sometime referred to as the "UV-Aging" (as opposed to the UV-Burning) rays. Even though the UVA rays do not cause a direct damage to the cell's DNA, they harm it indirectly by producing free radicals that then, in turn, lead to skin aging (wrinkles, age spots, elasticity loss), inflammation and DNA damage. By doing so, UVA rays increase one's risk of skin cancer.
This means that our skin needs protection from both the UVB and UVA light. It is important to remember that not all sunscreens can protect from both the UVB and UVA light. In fact, until recently, the filters used in sunscreens offered a meaningful protection against the UVB rays only. Luckily, in the recent decades, scientists have been working hard on developing new sunscreen filters that would offer a broad spectrum protection (meaning protection against both the UVB and UVA rays). These new sunscreen filters are widely used in sunscreens today in most parts of the world (with the exception of the US, unfortunately: most of these new generation filters are not approved by the FDA yet and cannot be incorporated in the sunscreens sold in the country).