A vessel of water stays by the bed so that a person can wash his hands before he walks more than four cubits (Shulchan Aruch, Orach Chayim 4:2). The custom is old, and the Sages and the Kabbalists gave reasons for it that do not quite overlap.
The spirit on the hands
The Kabbalists, following the Zohar, teach that when the soul leaves the body at night, a spirit of impurity settles on the hands, and water removes it. The hands look clean in the morning, which is why the law does not depend on what a person sees. The washing is required whether or not he touched anything unclean in his sleep. Our article on the spiritual worlds and protection from evil covers how the Kabbalists describe such forces.

How it is done
The water is poured from a vessel, three times on each hand, alternating between them. Communities differ on which hand goes first, and a person should follow the custom of his own. The hands are dried, and then the blessing is said: al netilat yadayim, “on the washing of the hands.” The Kabbalists link the ten fingers with the ten sefirot (Divine attributes), and the Arizal recorded specific intentions for the washing in Sha’ar HaKavanot.
The washing comes after Modeh Ani and before Asher Yatzar. It is repeated after using the restroom, and again before eating bread. A related and more demanding form of purification is described in Deep Secrets of the Mikvah.