You may have wondered why our pinnae (the visible parts of the ears; singular: pinna) are shaped in such an odd manner. It turns out that there is method in this madness, as this odd shape selectively changes the quality of the sound entering the ear, according to the sound's original direction. It does this by altering certain specific frequencies. So the same sound coming from above you is modified in a different way than it would if it were coming from below you. Ditto for in front vs behind you. The brain is able to interpret these subtle changes and pinpoint the sound's source along these two axes.
The remaining axis - left vs right - is determined by two entirely different methods.
Firstly, sounds originating from the right will be slightly louder to the right ear than to the left (since sounds get softer the further away from the source you are). Secondly, a sound from the right will reach the right ear slightly before it reaches the left ear. The reverse obviously applies to a sound coming from the left side. The brain uses these two facts of physics to tell where along the left/right axis a sound comes from.