Browsing the archives I ran across this enchanting question right away. To my surprise, this question had developed quite a lot of controversy, with three alternate explanations – none of which agreed with what I think is the best explanation.
The eyes of different animals work in very different ways. This is because they have different priorities. A frog, for example, basically does not see objects that do not move. But if a fly zips by its field of vision, it can focus on it very accurately, discern the fly’s location and zap the fly with its tongue.
The vision of birds works in a similar way. Unmoving objects are not a threat, but moving objects are. Hence, birds see moving objects better. A hawk sees the slight movement of a field mouse from unbelievable distances. A pigeon notices the movement of a predator and takes flight.
In order for the pigeon to notice the movement against the background, it must bob its head when it walks. When its body is moving forward, it moves its head backwards in order to keep it stationary in relation to the ground. Then it brings its head back forward very fast for the next step. This way the background is unmoving for most of the time even with the pigeon walking, and it can easily see motion.
This behaviour is more noticeable in some other birds, especially certain species found on the African savannah. These birds have longer necks, and the bobbing is therefore much more noticeable.