The Shire knows Gandalf the Grey as a funny old man who puts on fantastic fireworks displays. Frodo knows him as a friend and a mentor, full of wisdom and humor. Théoden and Denethor both accuse him of meddling, of manipulating the lives of men and affairs of state. They are all right. He begins the quest by identifying the Ring and is the first to say that it must be destroyed. He guides the Fellowship until his fall in Moria — and when he defeats the Balrog and returns, he continues to guide events. It is Gandalf who rouses Théoden from his stupor and Gandalf who brings the Ents and reinforcements to Helm's Deep just in time to win the battle. Gandalf confronts the Nazgûl and leads the defense of Minas Tirith. He rescues Frodo and Sam from the slopes of Mount Doom, and he leads Aragorn to the sapling of the White Tree.
How does he do this? Gandalf is a wizard, probably the most powerful individual in Middle-earth other than Sauron himself, but what exactly does that mean? Gandalf and Saruman, the two wizards described in detail, are not just men who study magic and spells. They seem to share the immortality of the elves, and they do not age or change. After the Ring is destroyed, Gandalf says simply, "My time is over: it is no longer my task to set things to rights, nor to help other folk to do so." Wizards are not human; they are spirits in human form, who exist on earth to accomplish a specific purpose and leave when they are done. To learn more about the wizards, their powers and their origins, read the Silmarillion, Tolkien's account of the creation of his world.