Before and during the First Age, Sauron was in origination an "angelic" spirit called a Maia? in Tolkien's invented mythology. He was at first a powerful servant of Aulë the Smith, an even greater angelic spirit, one of the Valar?, or ruling powers of the world. However, Sauron was among those soon subverted by Morgoth, an evil Vala?, and Sauron himself turned to evil. Ever after, Sauron served Morgoth faithfully, and even in later days, after Morgoth was defeated and locked outside the confines of the world, Sauron encouraged and coerced men to worship Morgoth as god.
During the First Age, the Noldorian Elves? left the Blessed Realm of Valinor in the Utter West (against the counsel of the Valar) in order to wage war on Morgoth, who had stolen the holy Silmarils, enchanted gems that glowed with light, from them. In that war, Sauron served as Morgoth's lieutenant. Known as Gorthaur the Cruel, Sauron at that time was a master of illusions and changes of form, and werewolves were his servants. He conquered the Elvish isle of Tol Sirion, so that it became known as Tol-in-Gaurhoth, the Isle of Werewolves. There later Finrod Felagund, the elven king of Nargothrond, died protecting Beren in captivity; soon afterward Luthien and Huan the Wolfhound defeated Sauron in that place and rescued Beren from the dungeons into which Sauron had thrown him. After his defeat by Luthien, Sauron played little part in the events of the First Age, and after his master Morgoth was defeated and cast out by the Valar, Sauron repented and pled for mercy. But he was unwilling to return to the Utter West for judgement, and he fled and hid.
During the Second Age, Sauron put on a fair visage, and calling himself Annatar, the Lord of Gifts, he befriended the elvish smiths of Eregion, and counseled them in arts and magic. Then the elves forged rings of power, but in secret Sauron forged the One Ring to rule the elvish rings, investing most of his own power into the Ring as he forged it. When Sauron put on the One Ring and tried to dominate the elves, they resisted, and Sauron came upon them with war and defeated them. In this time Sauron founded his realm in Mordor and, towards the end of the Second Age, assumed the title of King of Men. This offended the Numenoreans, the powerful men descended of Beren and Luthien, who lived on the island of Numenor in the sea between Middle Earth and Valinor. The Numenoreans, who were then proud, came to Middle Earth with astounding force of arms. Sauron's forces fled, and Sauron was taken as hostage to Numenor. There, wielding the One Ring, he quickly grew from captive to advisor; he converted many Numenoreans to the worship of Morgoth, and raised a great temple in which he performed human sacrifices. Finally, he convinced the king of Numenor to rebel against the Valar and attack Valinor itself. Eru, that is, the supreme god, then directly intervened -- Numenor was drowned under the sea, and the great navy of Numenor was destroyed. The world was bent, so that thereafter only elves could sail into the Utter West. Sauron was diminished in the flood of Numenor, and fled back to Mordor, where he slowly rebuilt his strength. A few faithful Numenoreans were saved from the flood, and they founded Gondor? and Arnor in Middle Earth. These faithful Numenoreans, Elendil and his sons, allied with the elven king, Gil-Galad, and together fought Sauron and, after long war, defeated him, although both Elendil and Gil-Galad were slain. Isildur, son of Elendil, cut the One Ring off Sauron's finger and claimed it. But later the Ring betrayed him, so that Isildur was slain by orcs, and the Ring was lost for centuries.
In the Third Age, Sauron rose again, at first in a stronghold called Dol Guldur, the Hill of Sorcery, in Southern Mirkwood. There he was known as the Necromancer, and the elves did not realize at first that it was actually Sauron returned. Gandalf? the wizard stole into Dol Guldur and discovered the truth; then the White Council of wizards and elves put forth their might and drove Sauron out. But he simply moved back to Mordor and raised again his dark tower, called Barad-Dûr. He fortified Mordor and prepared for war against Gondor and the elves.
Sauron bred immense armies of orc?s. He allied with and enslaved men from the east and south. He gathered his most terrifying servants, the Dark Riders, or Ringwraith?s, each wearing one of the nine rings designed for mortal men. Sauron adopted the symbol of a lidless eye, and he was able at that time to send out his will over Middle Earth, so that the Eye of Sauron was a symbol and power of fear. But he was defeated when his One Ring, found by Bilbo the Hobbit, was cast by Frodo, Bilbo's nephew, into the Crack of Doom in Morder where it had been made. Then Sauron's power was unmade, and his corporeal power in Middle Earth came to an end.
See also Akallabêth, Of the Rings of Power and the Third Age.