Ian McKellen's Gandalf — both Grey and White — is one of the most realistic portrayals of a novel character on the big screen. The wizened wizard is one of the many focal points present in The Lord of the Rings, holding the story together with nothing more than sensible maxims and a magic staff.
Gandalf's character according to Peter Jackson takes a slightly different route, with a few alterations made in terms of his backstory, allies/enemies, and his general emotional state. Nevertheless, the divergences are noticeable, especially for fans of the books, even if there isn't much to complain about.
Different: An Angelic Past
Movie Gandalf was nothing more than a "wizard," a mystical profession whose roots remain uncovered. Originally, this decrepit-looking man doesn't look as ancient in the novels, although he's probably older than every being on Middle-Earth.
Gandalf was part of Iluvatar's creation symphony, one of his Ainur (or angels) who helped in the composition of Arda (the world). Known as Olorin of the West, he became a Maia upon leaving the Timeless Halls and was considered to possess unmatched wisdom and piety: all learned from the Vala Nienna.
Same: Quirky Old Man
Gandalf is easily infuriated, but just as quickly lets go of his temper in favor of good cheer and playfulness. He truly believes that harmony must be established to right all the wrongs created by the denizens of Middle-earth, although the routes he regularly takes are quite convoluted and almost indecipherable.
Most importantly, Gandalf in either case continues to spout great wisdom in addition to his various bizarre performances. He might have a tendency towards scolding people for their lack of responsibility but simultaneously lauds them for doing the right thing.
Different: The Wielding Of Narya
There is no mention in the films of the Ring of Fire crafted by the Elf Lords during the Second Age, but Narya does appear on Gandalf's finger while he and Frodo plan to leave Middle-earth for good.
He first obtains it from the ancient Elf, Cirdan the Shipwright (another missing character), who hands him the ring upon their initial meeting itself. This is because Gandalf's inner Maia is somewhat visible to Cirdan, who expects that Narya might help the wizard with his inevitable battle against the forces of Sauron.
Same: Guides The Fellowship
There is no Fellowship without Gandalf, which automatically means that there is no victory to be had if the old man does not actively lead the other eight members of their motley group.
During Elrond's council at Rivendell, a decision is made to send those with the highest stakes in the upcoming war along with the Ringbearer, including representatives from the Elves, Dwarves, Dunedain, Gondor, and the Shire. Gandalf pretty much carries the weight of the Fellowship for most of the first book/movie, at least until he "perishes" at the hands of Durin's Bane in the abyss below Moria.
Different: Always Anxious
It's a reasonable decision to generate feelings of sympathy for a particular character by giving them explicitly human traits, be it mild uneasiness or full-blown anxiety.
But Gandalf is not human in the books, as already mentioned, and therefore does not really react with fear under most situations, regardless of how bleak the outlook seems to him. Tolkien intended for him to have a largely logical mind, making decisions on behalf of the whole world even if it meant "manipulating" a few innocents into going on unwanted quests.
Same: Undergoes A Metamorphosis
After a laborious battle with the Balrog of Khazad-Dum, Gandalf the Grey breaks the infernal beast against the Caradhras slopes, but the energy expenditure on his part is far too high for continued survival.
Nevertheless, given that Middle-earth desperately needs his advice and leadership, Iluvatar reincarnates him into Gandalf the White: a far superior variant with increased access to his angelic powers (that were originally diminished by the Valar in order to prevent him from succumbing to the allure of power).
Different: Not As Powerful
It's not like Gandalf can't make mistakes once in a while, but having him actually lose to an opponent far below his level is a strange character deviation, indeed. The leader of the Nazgul or Ring-Wraiths, also known as the Witch-King, is shown to "defeat" the wizard (until he is saved at the last minute by Eomer and his men.)
Gandalf is not nearly as weak in the books; in fact, he has proven in a number of ways that he possesses the power to potentially challenge Sauron himself, let alone one of his minions.
Same: Still Badass
Gandalf is the greatest wizard in Middle-Earth, considerably more than Saruman after receiving his tonal upgrade from dirty gray to blinding white. The oft-quoted line before his alleged death — "You shall not pass!" — is a clear indication that he is both courageous and confident enough to hold his ground against the Balrog of Morgoth (the once and forever OG Dark Lord).
Not to mention his devotion to the role given to him: when it becomes apparent that his fate lies elsewhere, he pressures the Fellowship into leaving him behind, telling them to "fly, you fools!"
Different: The Battle With Saruman
Although Saruman may have been smarter than Gandalf, the latter was undeniably more enlightened. In the films, these two characters have a telekinetic brawl with each other, with Saruman winning after separating his opponent from his staff.
On the contrary, the novels show Gandalf not even trying to fight, because he is fully aware that his adversary has skills beyond his own imagination. At the end of their interaction, rather than "flying" to the top of Orthanc tower, Saruman has his "soldiers" transport Gandalf to his roof-prison.
Same: Loves His Fireworks
Being a representative of the element of fire (the "wielder of the Flame of Anor" and all that), Gandalf has a predilection towards fireworks. He creates some of the most exquisite pyrotechnic patterns, usually offering them to the Hobbits during their various celebrations, for instance, Bilbo's party and the Midsummer-eve festival.
Gandalf's premier achievement in this field has to be his incredible Dragon firecracker, producing a life-like beast that temporarily terrifies the Hobbits (but does nothing to put a damper on their merriment).