There are two types of melanin, namely red pheomelanin and black eumelanin, both of which are present in human skin. However, only eumelanin protects skin from UV damage, while pheomelanin can actually generate free radicals which might contribute to skin damage.
Not every cell in the body produces melanin - skin cells that do, are called melanocytes. In most people melanocytes are spread evenly across the skin, but some people have melanocytes in clumps in the skin. These clumped melanocytes don't produce the UV-protective eumelanin, as they have a mutation in a gene that is essential for regulating the proportions of pheomelanin and eumelanin. Usually this proportion is controlled by a hormone called melanocyte stimulating hormone (MSH). This hormone binds to a specific receptor on the surface of the melanocyte cell called MC1R (A in the illustration on the right). When MSH binds to MC1R signals are sent into the cell to turn pheomelanin into eumelanin. When there is a mutation in MC1R, the MSH can't bind to it, and pheomelanin isn't turned into eumelanin (B in the illustration on the right). This causes the reddish colour of freckles.
The MC1R mutation is dominant, meaning that you only need one copy of the gene to have freckles. However, red hair is a recessive trait, which means that you need two copies of the MC1R gene to have red hair.
A recent interesting paper has determined that variations in MC1R caused variation in hair and skin pigmentation in Neanderthals on a scale that is observed in modern humans.1
Photo above: Cyclist's tan with freckles. The skin is freckle-free where a watch fits around the wrist and on the hand where cycling gloves cover the skin.
If you want further information on skin pigmentation and melanoma (cancer), you can go here.
1 Lalueza-Fox C et al.
A Melanocortin 1 Receptor Allele Suggests Varying Pigmentation Among Neanderthals