And this is the same class of animal that can confuse a cardboard box with its mother!
Though the pigeons' homing instinct has been known for centuries (news of Napoleon's defeat at Waterloo reached England first by carrier pigeon), only fairly recently have we begun to understand how bird navigation works.
If we think anthropomorphically, we're likely to assume that birds orient themselves relative to important landmarks, as we humans do. However, radar can pick up flocks of migrating birds, and radar evidence shows that migrants largely ignore important geographical features such as bends in major rivers and curves in coastlines. Clearly, birds have something else going for them.
It's been found that birds can determine directions according to the position of the sun. Many bird species seem to have "internal clocks" enabling them to behave as if they were making mental calculations something like this: "It's noon, so the sun has to be directly south, and if the sun is directly south and I need to fly toward the west, then I have to fly so that the sun is on my left... "
The classic experiment proving the internal-clock theory was done by German Gustav Kramer during the early 1950's, who placed caged Starlings wanting to migrate so they could see the sun. The birds would sit looking in the direction toward which they wanted to fly. Significantly, if the Starlings couldn't see the sun, they didn't face in any particular direction.
Also during the 1950's, the German Franz Sauer did a similar experiment with birds who could and could not see the night stars. The results were the same: Certain species can orient themselves according to the sky's major stars. In fact, an experiment with Mallard Ducks found that if the moon is so bright that important stars are hidden by glare, released ducks can't orient themselves as well as on darker, moonless nights.
Can birds orient themselves relative to the Earth's magnetic field? During the early 1970's, W.T. Keeton did a series of elegant experiments to get the answer. Onto the backs of one group of pigeons he glued small, non-magnetic brass bars. On the backs of a similar group he glued miniature magnets which, he thought, might disrupt the Earth's magnetic field in the vicinity of the pigeons. When released at locations the birds had never seen before, the pigeons with non-magnetic brass bars found their ways home much better than those with magnets on their backs.
In a 2007 article in the German journal Naturwissenschaften scientists announced that they'd found tiny iron oxide crystals in the skin lining of the upper beak of homing pigeons, laid out in a three-dimensional pattern in a way that the birds might be able to sense the Earth's magnetic field independent of their motion and posture, and thus identify their geographical position.
Therefore -- certain birds can definitely use the sun, the stars, the Earth's magnetic field, and who knows what else, to find their ways home. Once they're very close to home they probably also notice local landmarks, and navigate to their very nests the way a human might, though that's just an anthropomorphic guess...
Very much is not known about bird migration. Also, only a few bird species have been studied, so it's risky to apply what little is known to all species. Finally, it can be assumed that migrating birds typically use more than one method. They probably use the technique that feels most accurate at the time.