A tan is a natural mechanism of the human body to guard itself against the harmful UV rays of the sun. When we sit outside in the sun for long periods of time, the body starts acquiring a dark color, commonly referred to as a tan.
What actually happens when we sit under the sun is that the body's melanocytes start producing the darkening pigment known as melanin. This melanin pigment absorbs the UV rays and thus protects the skin from sun damage.
There are two types of rays emitted by the sun which can cause tanning- UVA and UVB. It is the ultraviolet A (UVA) rays which are responsible for much of the tanning and skin aging and can lead to a dangerous type of cancer known as melanoma. Usually the sunscreens offer very little or almost no protection against these rays although clothing is supposed to offer some kind of protection. It is present more uniformly throughout the day as compared to the ultraviolet B (UVB) rays.
It is actually the Melanocyte stimulating hormone (MSH) produced by the pituitary gland which stimulates the production of melanin. If the secretion of MSH is high, the body becomes darker in color. Another hormone called ACTH can also lead to the production of melanin.
Melanocyte production also depends a lot on the race. In some races, such as the Caucasians, the skin produces very less amount of melanin. Also, it gets burnt instead of getting tanned, when exposed to sun. In some other races, melanin production is continuous, whether the skin may get exposed to sun or not. So, they always have a somewhat tanned skin. Hence, fair-skinned people who want to get a tan have to have patience. Because however fashionable it might be, it is not possible for them to get 'that perfect tan' in a day.
The UVB rays on the other hand can also lead to certain forms of cancer, skin aging (although, considerably slower as compared to UVA), wrinkles and moles as well. Yet moderate exposure to these rays is beneficial to the body. Almost all the sunscreens offer protection against the UVB rays.
There are also UVC rays which are present in the environment. But, they get filtered out and never reach us.
The melanocytes actually produce two different kinds of pigments- eumelanin and phaeomelanin. It is the eumelanin which is responsible for giving the tanned look. The redheads produce more of phaeomelanin which is why they don't get tanned quite easily. As for the Albinos, because of lack of an enzyme called tyrosinase, the melanin-producing pathway is blocked and thus, they do not have any pigment in their hair, skin or even irises.
Though, tanning is actually a mechanism of the body which protects it against the harmful UV rays. But as excess of anything is bad, so overexposure to the sun is also harmful.