The Lord Of The Rings: How Gandalf Comes Back To Life Explained
In "The Fellowship of the Ring," Gandalf falls in an epic battle with the Balrog of Moria. Then, he makes a miraculous return in "The Two Towers" as Gandalf the White. While we get a little context in the movies, Tolkien's books help explain how this is possible. The short version is that Gandalf can come back to life because he never really dies in the first place. He's an immortal being in a physical body, and while that body temporarily fails, the immortal being is ultimately sent back to Middle-earth to finish his quest.
Again, if that sounds confusing, we get it. Let's back up a bit. Gandalf's original name is Olórin. He is a member of a spiritual race of angelic beings called the Maiar. In "The Silmarillion," Tolkien says these are spirits who pre-exist Middle-earth and enter it when it's created. They support the Valar (the angelic guardians of the world) as their servants and helpers. The Valar and the Maiar aren't made of physical matter. However, they can take on physical forms. Sometimes, this is done casually. At other times, it's done to intentionally limit their powers, as is the case with the Wizards.
The book "Unfinished Tales" explains how the Wizards were "clad in bodies as of Men, real and not feigned" to help the Free Peoples of Middle-earth resist Sauron. It adds, "though because of their noble spirits they did not die." So, while Gandalf is an immortal spirit, he is specially chosen as one of the Five Wizards to embody a physical old-man form to help resist Sauron. When that form fails in the fight with the Balrog, the spirit of Gandalf leaves that body, only to be sent back to finish the job, since he's the only Wizard actually on task during "The Lord of the Rings."
Does Gandalf's Body Actually Die in The Lord of the Rings?
Considering the unique makeup of Gandalf as an immortal being in a mortal body, a fitting follow-up question is whether he actually "dies" at all. The straight answer is that yes, his physical body really does die after a long fight with the Balrog (who is about to get a voice in "The Rings of Power" series). Gandalf remembers this (in "The Two Towers" book), saying, "Then darkness took me, and I strayed out of thought and time, and I wandered far on roads that I will not tell." He continues, "Naked I was sent back – for a brief time, until my task is done." He talks about being alone on the mountain top for a while, stranded and forgotten, where "each day was as long as a life-age of the earth."
Multiple times in the story after this point, Gandalf references his "death." When he confronts Wormtongue in "The Two Towers" book, he says, "I have not passed through fire and death to bandy crooked words with a serving-man till the lightning falls." Later in the book, he tells Saruman, "I am Gandalf the White, who has returned from death." This comes up again in a timeline of events in the appendices of "The Return of the King," where Tolkien says that Gandalf "casts down the Balrog, and passes away. His body lies on the peak," adding, "Gandalf returns to life, and lies in a trance."
Finally, in a letter in 1954, Tolkien explicitly says, "Gandalf really 'died', and was changed." He also says, "So Gandalf sacrificed himself, was accepted, and enhanced, and returned." Critically, he adds that the Valar aren't the ones who send Gandalf back the second time. Instead, the author says in the letter that Gandalf is sent back by "Authority" (i.e., the Creator of the world) to finish his task.
The Balrog incident is just one part of Gandalf's in-and-out-of-body history
While Gandalf's death and return in "The Lord of the Rings" is a big deal, it isn't his first time taking on a physical form. "The Silmarillion" says that, as Olórin, he loved the Elves very much and, early in Middle-earth history, "he walked among them unseen, or in form as one of them, and they did not know whence came the fair visions or the promptings of wisdom that he put into their hearts." So, early on, Gandalf spent a lot of time in and out of a physical Elf-like body.
Olórin is also selected as one of the Five Guardians who help protect the Elves early in their history — although it isn't made clear if he's in a physical form or not at this point. Tolkien doesn't say much else about Gandalf before the Third Age, when "The Lord of the Rings" takes place. In fact, having Gandalf show up during the Second Age is one of the biggest book changes the "The Rings of Power" series has made so far.
While Gandalf's ending after "The Lord of the Rings" isn't clear, we do know that he heads back to the Blessed Realm over the sea in the West. Once there, he likely doesn't stay in his old-man body. He probably returns to his previous lifestyle, spent mostly in spiritual form, with the occasional exception of taking on a physical form so he could visit with his Elvish (and Hobbit) friends.