Special cells called melanocytes create this pigment and push it out of the cell where it darkens the skin, giving us a brown tan and also absorbing the damaging UV rays.
Over time our tan will fade as the darkened skin layers are pushed upwards by new cells that contain less of the brown melanin.
If our exposure to UV radiation exceeds our body's ability to protect the skin through this melanin tanning process, the radiation results in permanent damage to the DNA of skin cells.
Detecting this damage, the body tries to repair the area by prompting the body to increase blood flow, which creates warmth and a redness to the skin. The body also activates its inflammatory response by sending immune cells to the damaged tissue, resulting in pain that it's hoped will encourage us to stay out of the sun for a while.
As individuals, we all respond differently to sun exposure and the genetic basis behind our response could help to predict whether or not individuals are more likely to be at risk of skin cancer over their lifetime.
New research published in the journal Nature Communications used genetic data from almost 200,000 people of European ancestry who reported whether their skin-type burned or tanned easily.
As one of the largest studies of its kind looking at the genetics of sunburn, the huge amount of data allowed scientists to compare the genetic variability of a diverse group of people and see how these genes were responsible for protection from the sun.
It was already known that people who tan easily have more protection against DNA damage from the sun, and with smart lifestyle choices such as protecting themselves from too much sun exposure, were at a reduced risk of skin cancer.
However, this study was also able to identify almost all the genes involved in skin tanning, which included 10 new genetic regions not previously identified.
The results suggest the development of skin cancer can occur via two pathways: one dependent on skin pigmentation and the other independent of tanning ability.
This new information could help scientists understand the genetic risk factors involved in the most common cancer in our country.
With so much new data, the potential to create a simple genetic test that profiles a person's biological risk of developing skin cancer is possible and could help individuals to understand the seriousness of managing their sun exposure.
Dr Michelle Dickinson, creator of Nanogirl, is a nanotechnologist who is passionate about getting Kiwis hooked on science and engineering. Tweet her your science questions @medickinson