As the brain notices an increase in natural sunlight, Melanocyte Stimulation Hormone (MSH) is released to produce melanocytes in the skin, which in turn, recognize the presence of UV radiation, and produce melanin to absorb the rays.
The melanin in your melanocytes is stimulated by the ultraviolet rays in the sunlight by absorbing harmful UV radiation to stop it from affecting other cells in your body. In "white" skin, the production of melanin is over a period of time.
Melanin levels typically don't reach the protective level until exposure for the better part of a week. In some races, the melanin levels are far higher, and pigment is present in the skin all the time, hence prevalence of skin cancer are far lower than the norm in some races.
Technology now has brought artificial suntanning indoors in places called solariums, using lights and lamps that emit radiation similar to that of the sun including the UV part. Some of these actually emit some rays up to 5 times the strength of the sun.
There is now evidence of very adverse effects resulting from using solariums to get artificial suntanning notwithstanding the fact that the client maybe is being exposed to too strong radiation for too long or too frequently during treatments.
The perpetual question of which tanning method is safest lingers. Strong arguments are presented on both sides, however.
There is also now a new breed of tanning salon using rtificially produced tans which have absolutely nothing to do with sunlight or solarium beds. These treatments are from using dyes and sprays resulting in a "fake" tan.