The general Japanese word for “ghost” is Obaka, which comes from the honorific “o” and the verb “bakeru,” or “change.” Thus, a Japanese ghost is a transformer; something that changes from one form to another. There is a rich and almost endless body of folklore detailing all kinds of ghosts and spirits.
The type of Japanese spirit which most closely resembles our idea of a ghost is a Yurei. Yurei are spirits of the dead who return to earth for some reason, usually vengeance. They are most commonly seen between 2 and 3 A.M.
In the Shinto religion, all people are endowed with a soul, or reikon. As long as people are given a proper burial, this soul joins the souls of its ancestors when it dies, and is at peace.
However, if a person dies suddenly or unexpectedly, or if there is no proper burial, these souls become ghosts, or Yurei, which remain on the earth to take care of unfinished business, or to seek revenge.
In the earliest recorded stories, these Yurei looked like the living entity they once were. But in the 17th century, when kaidan (ghost stories) became popular in literature and on the stage, they began to be represented with certain characteristics, mostly taken from the funeral rituals of the Edo period. This was mainly done for convenience, to make it easy to tell the difference right away in stories and rituals. It may have little to do with how spirits have been actually seen in Japan. For instance, they are usually dressed in white, because white was the burial color in the Edo period. They wear plain, unadorned kimonos called katabira, or more elaborate ones that are covered with Buddhist symbols. They also usually have a white strip of cloth or paper around their foreheads; this is a part of Buddhist funeral ritual which used to be for protection of the dead against evil spirits.
In the 18th Century, Yurei began to be portrayed without legs. Actors of the time would wear long kimonos to cover their legs and sometimes hang from ropes. Today in anime, Yurei are usually portrayed without feet. This is just a storytelling and theatre convention to make the Yurei spookier. However, it should also be noted that legs give a person contact with the earth, and suggest roots. The Yurei are rootless.