Think about it this way; you as a human being, for the most part only have 2 audio inputs.
So how is one able to distinguish if a sound is in front or behind them?
As best stated above; voodoo magic.
In all seriousness though , the ears are some weird pieces of tech, and aren't too easy to...