Today, I'm watching old episodes of BBC's Merlin in deference to today's question from the audience, which goes like this: What is the origin of the bearded old wizard archetype (Merlin, Gandalf, Dumbledore, etc.)?
There's no specific gospel answer to this question; the modern image of the beardy wizard draws from various different sources and has roots in various cultural and literary traditions, so it's a sort of potpurri result of different ideas being combined and distilled. It goes back quite a ways into history and is especially popular and widespread in European traditions, which is where all the wizards named above come from.
The oldest and probably most universal source of the image is the idea of age, visually shown via a long beard, conferring wisdom. In most ancient cultures, older people were respected and considered to have great wisdom, which they had acquired by living longer than everyone else and collecting knowledge over the many years of their existence. Many cultures deferred to their elders as the wisest and most important advisors among their number for this reason, and this was often extended to assuming that they gained superhuman powers.
Wisdom, knowledge and secrets were in many myths and legends synonymous with magical power, which was assumed to be gained from learning occult lore or secret spells that the common folk didn't know, so therefore it only made sense to assume that if elderly people were the wisest people, they would also be the most likely to be magicians. This is also responsible for the trope of the old, crone-like witch - like the bearded wizard, she is represented as advanced in age in part to illustrate the fact that she has access to magical knowledge that younger people do not have.
Of course, witches are also often represented as beautiful and sexually alluring, but that's a whole other issue revolving around the idea of sex appeal being the most important power a woman could hold and the only way they could overpower a man, and could easily be its own blog post.
You may have noticed that beards in artistic representations of wizards tend to be comically long - not just the kind of long that indicates lackadaisical grooming habits or being too busy scholarizing to tend to one's hair situation, but the kind of long that is usually not found in most human beings even if they are intentionally growing their hair long. Often, this is an artistic device to suggest that the wizard is older than a human could normally be, and that they therefore have knowledge and sorcerous skill that even the oldest among normal people couldn't have. That doesn't necessarily mean that all wizards are considered to be older than humanly possible (exceptions such as Merlin aside), but to show them as symbolically exceeding human limitations because of their power, or to suggest that their arts have allowed them to extend their lifespan, therefore increasing their wisdom and power, in a neverending cycle of getting older and more magically badass as they go.
This has led to various people who wanted to be considered wizards - the sixteenth-century magician John Dee, for example - intentionally growing out their beards in order to suggest that they were especially sagacious, and to artists adding embellished beards onto figures they wanted to depict as being especially wise or magical even if they probably didn't have them in real life.
So when you see a wizard with a beard down to his toes, what it's symbolically telling you is that he's incredibly old and venerable, and that that makes him extremely magically potent. The more beardy he is, the more powerful he probably is. He's keeping his spells in all that extra bushiness.
The idea of age equating to wisdom and therefore power is one that appears frequently around the world, but the bearded wizard is especially popular in European myth and folklore, and it probably owes that extra popularity to the figure of Váfuðr, the form of the Norse god Odin that appears as a bearded old man, wandering the world to learn new knowledge while undercover. Odin's wandering old man image has often been represented in art as being wildly bearded, not only to suggest his age and wisdom but also to play up his status as an unkempt pilgrim in the wilderness. This version of Odin has an enormous influence thanks to serving as the archetypal original wizard for many later works to base their portrayals on.
In fact, one of the later popular wizards you mentioned, Tolkien's Gandalf, was certainly at least in part based on Odin; Tolkien himself referred to the character as "Odinic", and the two wizards share many features in common as well as both being obviously rooted in Norse myth and lore.
The other contributor to the modern popular idea of the beardy wizard is Merlin, the wizard-advisor to the king in Arthurian lore, whose depictions certainly draw from both the template of Odin, whose religion was well-known in the British Isles and certainly influenced literature rooted there, and the general tradition of wizards as aged and therefore brainy. In older Arthurian stories, it's only occasionally that Merlin appears as old and bearded, often, just like Odin, because he is in disguise or transformed in order to perform some task. His age was exaggerated in later stories to make him more of an elder mentor figure to King Arthur, and to extend his range to allow him to be involved in stories over several generations of Arthurian characters.
The idea of the grey-bearded wizard is a very popular one at this point in history, especially in western culture; if you asked the average fan of fantasy literature to describe a wizard, odds are a giant beard would be pretty high on the list of attributes. This hasn't been the case throughout history, though, not even for all of these characters we've been talking about. Merlin, for example, is often shown as young and fair-faced, which instead of painting him as a figure who has acquired great wisdom with great age instead portrays him as one who draws power from his youthfulness and strength - or, when he is old but not bearded, because beards were out of fashion on and off through history, and the artist didn't want to make Merlin look scraggly or like a peasant by standards of the time.
Of course, this is all very Europe-centric. Beards have had a variety of different meanings in different cultures around the world, and their symbolism doesn't always match up to the European idea of the bearded wizard. Occasionally it's in direct opposition, such as in ancient Egypt, where facial hair was usually shaved off to avoid lice and mock beards were worn to indicate nobility instead, or in warrior cultures such as the Mongols wherein beards were considered marks of virility and honor in battle rather than being associated with wisdom.
But if you're looking to be a wizardly kind of a hero and you're wondering if rocking the beard is a valid mythological choice, wonder no longer. You'll be keeping company with the All-Father, and it's hard to get more wizardly than that.