Gandalf's true name is Olórin, a wise Maia spirit from the Undying Lands. He was a pupil of the Valar, Nienna, who taught him pity and patience.
Olórin was one of five Maiar who were chosen by the Valar to travel to Middle-earth to aid the free-peoples against the return of Sauron. Known as Istari, they were forbidden to dominate the races of Middle-earth through mind or might or to match Sauron's power with power.
Upon arriving on Middle-earth at the elven port of Mithlond, the Istari were greeted by Círdan the Shipwright as well as his elf friend Glorfindel. Círdan who said although Olórin was the frailest of the five, he appeared the wisest and to have the most inner strength, because of this Cirdan gave him the gift of Narya, one of the 3 elven rings of power.
On Middle-earth the Istari became know as Wizards and Olórin himself was know by many different names by different people Mithrandir in Gondor, Stormcrow in Rohan but was most commonly known as Gandalf to Hobbits. For over 1000 years he walked among the Elves teaching them and learning their ways. He is renowned for his fascination in Hobbits.
Burglar Baggins and the Return of Sauron
Many years later he helped the Hobbit, Bilbo Baggins and 13 Dwarves on a quest to slay the Smaug the Dragon and recover their treasure under the Lonely Mountain. It was during this quest when Bilbo Baggins discovered the dagger, Sting, and the One Ring, although Gandalf did not realise its true identity at the time, and Gandalf himself discovered the sword, Glamdring.
During this adventure Gandalf traveled to southern Mirkwood to join the White Council at the Stronghold of Dol Guldur to oust the Necromancer. It was Gandalf himself who discovered that the Necromancer was none other than Sauron.
Some 80 years after the slaying of Smaug, Gandalf had realised the magic ring that Bilbo discovered was none other than the One Ring, a powerful ring that would allow its maker, Sauron, domination over Middle-earth forever. The Ring had long been passed onto Bilbo's nephew, Frodo. After revealing its true identity to a frightened Frodo he told him to leave the Shire and head east to the elven outpost of Rivendell. Gandalf traveled to Isengard to seek the council of the wizard Saruman.
After he told him of his discovery of the One Ring, Saruman revealed his true intention of finding the Ring for himself and ruling Middle-earth. When Gandalf refused a battle ensued, however Saruman had the superior powers, and after overpowering him imprisoned him in Isengard, so he couldn't assist the Hobbits, he did however send the ranger Strider to aid them. He was inadvertently rescued from Isengard by his fellow wizard, Radagast the Brown, after he alerted the Eagles of Gandalf's journey there.
Council of Elrond
Gandalf rejoined Frodo and the One Ring at Rivendell. Thanks to Gandalf's guidance it was decided at the Council of Elrond that the Ring should be taken to Mount Doom, deep in Saurons domain of Mordor, and tossed into the fires. Only there could it be unmade and destroyed forever. A Fellowship was decided upon for this dangerous task, Gandalf, Frodo, Aragorn, Boromir, Gimli the dwarf, Legolas the wood elf and the Hobbits Sam, Pippin and Merry.
The Passing of Gandalf the Grey
During their journey they were forced to travel under the Misty Mountains through the abandoned Dwarven city of Moria. It was here were the Fellowship caught the attention of a Balrog, an ancient, powerful and dreadful creature from many ages past. Gandalf realized after entering Moria that it housed a dreaded Balrog, a creature which is also a Maia. Due to his knowledge of its power Gandalf realized he must stop and to defeat the fire-demon. As he smashed the bridge on which the Balrog stood with his staff.
However the Balrog's immense fiery whip grabbed him while the beast fell and pulled him down. The fellowship all believed he died from the fall, however Gandalf and the Balrog fought long in the bowels and deep places of Arda. Gandalf finally pursued the beast up the Endless Stair to the peak of Celebidil, where he fought the Balrog for two days and nights, atop Zirak-Zigil where he finally slew the beast and perished himself from exhaustion.
The Return of Gandalf the White
Despite the death of his body his Maia spirit could not perish. He was "sent back" by Eru because his task on Middle-earth was yet unfinished. More powerful than before he was now Gandalf the White to signify his new standing as leader of the White Council. Upon returning he called for a horse, and his call was answered by Shadowfax the Lord of all Horses, much to the distaste of Theoden, and his limitless endurance was soon put to use. He received his white robes from Galadriel in Lórien.
Gandalf the White's first task was to rally the Horse-lords of Rohan. With Isengard on their doorstep he knew that Sarumans armies would soon strike at the heart of Man. Upon arriving at Rohan, Gandalf discovers that King Theoden is under the spell and control of Saruman's agent, Grima Wormtongue. Breaking the spell, Gandalf convinces Theoden to take up arms against Isengard with all the men he can muster.
While Theoden and the Rohirrim ride to Helms Deep, Gandalf travels to meet with Treebeard to convince him that he is in need of the Huorns to defeat Saruman's army.
Power and Abilities
Energy Manipulation Gandalf has the ability to project vast amounts of energy in the form of a natural element, such as wind and lightning and water or more commonly fire (which is augmented by his possesion of Narya). Having had eons of practice he is deadly accurate with his projection and can deal large amounts of damage with them.
Energy Absorption Gandalf has displayed the ability to absorb both magical attacks from fellow Maia (e.g. Balrog and Saruman) and standard attacks (e.g. flames or waves) as well.
Weapon Master Gandalf has displayed proficiency in both his handling of his sword: Glamdring, and his staff. He survived the entire time he was in middle earth relatively unscathed and even defeated a Balrog single-handedly.
Gandalf on Film
Gandalf's first outing on screen was in the 1977 animated film, The Hobbit, where he was voiced by John Huston. The character soon appeared again the next year in Ralph Bakshi's The Lord of the Rings, this time voiced by William Squire. In 1980 John Huston reprised his role in the 1980 The Return of the King, to complete the 'unofficial' trilogy of animated films.
In Peter Jackson's The Lord of the Ring trilogy, Gandalf is portrayed by the British actor Sir Ian McKellen who appeared in all 3 films.