Tanning is the body's natural shield against uv rays.
Not to bronze your statuesque physique, although that may be why you tan. Tans are natural shields against the sun's ultraviolet radiation, which can damage skin tissue in the form of a sunburn (as well as cause cancer in the long-run).
Exposure to ultraviolet rays causes certain skin cells to produce the pigment melanin, which darkens through oxidation. Enough beach bumming and those cells will migrate closer to the skin's surface and produce more melanin, further darkening the skin into a suntan. It's no wonder our bodies have developed the ability to produce melanin.
The pigment absorbs ultraviolet radiation and defends against further penetration of skin tissue. In other animals melanin proves diversely useful. It absorbs heat, an essential for cold-blooded organisms. It colors bird feathers, fish scales and squid ink, and helps to conceal nocturnal animals. Melanin even absorbs scattered light inside the eye to sharpen vision.
But it appears that only humans will risk their skins for a little extra surface pigment.