Scientists aren’t positive about how this works, but there are many theories about the magnetic sense of birds. There are two main models: a radical-pair based model and an iron-mineral based model. This sense is used for migration and navigation, and other animals with magnetic sense include salamanders and newts, sea turtles, eels and fishes
On the iron-mineral based model of magnetoreception:
Fleissner et Al. 2007 concluded that there are two kinds of iron-based minerals in beaks, Magnetite (Fe3O4) and maghemite (Fe2O3). There are six patches in beak where iron minerals are concentrated, minerals are in the dendrites of neurons, on inner lining of upper half of beak.
How it works (speculations)
Magnetite forms micro clusters attached to cell membrane, maghemite has plateletlike structure arranged in chains inside dendrite1.
magnetite is ferromagnetic, senses the extremely faint magnetic field, maghemite platelets amplify the signal. The structure also contains an iron vesicle, the exact function of which remains unknown.
Here you have a close-up of these structures: http://tak-dev.appspot.com/lex/plos-paper_files/g001_m.png
Radical-pair based model
Involves a chemical reaction in the eye of the bird, which involves a radical pair.
A radical pair is a pair of molecules that each have one unpaired electron, making it sensitive to magnetic fields. In certain situations, the magnetic field can affect the products of the reaction.
Radical-based model: theory
Suppose products of the reaction affect the sensitivity of light receptors, resulting in brighter or darker regions in vision. It is known that the reaction affects light-sensitive chemicals called cryptochromes that are sensitive to blue or green light.
Ahmad et Al. shows that the sensing of magnetic fields works properly in blue light, but not in red light
Compare this system (or systems) in birds to an MRI, which is made up of a large superconducting magnet that creates a stable field and 3 smaller gradient magnets to create a variable field and allow portions of body to be scanned
So with this great sense that birds have, what can go wrong when navigating?
Well, many things. The bird could get eaten. Or they could be led off course:
Flamingos in Siberia- http://www.npr.org/blogs/krulwich/2011/03/07/134229725/flamingos-drop-from-siberian-sky-locals-mystified
Sorry if this is really technical, but I did take a class on neurobiology last year and thought I would share my knowledge! We got a project in that class to do a short presentation on senses of humans (or, in my case, other species- for me, birds! yay). Otherwise, I would not know the answer to your question.