I have spoken of the Power of Names in Fantasy but seldom about their creation, about how authors agonize in finding the perfect name for their characters. Ursula K. Le Guin, for example, would spend days if necessary to come up with a proper name, saying that without the name she cannot know the character. J.R.R. Tolkien was not quite the same to my knowledge, but in his many drafts of The Hobbit and The Lord of the Rings his characters and their names took on many forms. For example, when writing The Hobbit in the early 1930s Thorin Oakenshield's original name was Gandalf. So what was Gandalf's original name? Bladorthin! Small surprise he changed that one. Then, in the earliest unpublished versions of The Lord of the Rings, the character who became Aragorn was a Hobbit named Trotter. One can actually read some of those drafts in The History of Middle-earth (a 12 volume series of books compiled and edited by Christopher Tolkien), and seeing Trotter interact with Legolas and Gimli is fascinating. But the name Trotter lived on by evolving into the name Strider.
So where did Tolkien get his names? Depends. The name Gandalf along with the rest of the names of Thorin & Company (save Balin) were taken from the "Catalogue of Dwarves" section of the Völuspá. The Old Norse name Gandalfr incorporates the words gandr meaning "wand", "staff", "magic" and álfr ("elf"). Which shows that, for all that Tolkien is justly renowned for creating his own languages, he was not above using real-world ones since in Middle-earth itself Gandalf means in the tongue of the Northmen "Elf-of-the-wand" or more literary "Wand-elf". Why? Because in the early days of his wanderings Gandalf was taken for a very old Elf due to his immortality and deep friendship with them, and the name stuck.
"Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwarves, Olórin I was in my youth in the West that is forgotten, in the South Incánus, in the North Gandalf; to the East I go not." - Gandalf
Beyond that, Norse mythology notes a Gandalf Alfgeirsson who was a legendary king from eastern Norway and rival of Halfdan the Black. Gandalf is also the name of a Norse sea-king in Henrik Ibsen's second play, The Burial Mound, and "Gandolf" is a character in William Morris' 1896 fantasy novel The Well at the World's End, along with the horse "Silverfax". Hmmm... Silverfax. Now why does that sound familiar and why am I thinking of Shadowfax, Gandalf's noble steed, friend, and chief of the Mearas horses? Jokes aside, it brings up the interesting point that Morris' book deeply influenced Tolkien. Interesting because these days we talk chiefly about how J.R.R. Tolkien founded modern Fantasy literature and not what books and other tales inspired him.