We are able to detect the direction of sound because of our brain's capbility to measures the time lag and amplitude difference between the sound that reaches our ears. However the sound produced by a source 10 meters directly in front of us and sound produced by another source 10 meters directly behind us would produce the same effect on both our ears, but how do we distinguish the sound as coming from front and behind?
A couple of the answers above have parts of the information. The brain uses interaural, time, amplitude, frequency and phase differences to locate sounds. In the case of the sounds coming from behind you versus those in front of you, time, phase, and amplitude will be equal at both ears for the most part. However, there is a frequency difference due to the pinna effect. The pinna and the concha of the outer ear have a filtering effect for high frequency sounds. The pinna effect and the concha effect combine to gradually reduce sounds from directly behind you beginning at about 1200 Hz and effectively increasing slightly with frequency up to 8000Hz - 10,000 Hz. It is that slight differnce in high frequency amplitude that allows you to determine if the sound is from the front or back. However, it will require you to turn your head to do so. Just facing toward or away from a high frequency signal will give you the absolute amplitude information but not the relative difference from front to back. You need that relative difference to localize those sounds. as someone mentioned above, you can turn your head about 30 - 45 degrees away from a sound and it will get louder. That is the reverse of the pinna effect described here. That is why we naturally cock our heads a bit and raise our chins when we are trying to hear a very soft sound.
how do we distinguish the sound as coming from front and behind?
Good question. We don't. I'm often searching birds by sound in the field and I'm often confused with this. We often have quarrels with my girlfriend whether the bird was in front of us or behind :-) You have to turn your head to the side, little bit off the axis. That's also why some owls have their ears placed asymmetrically.
Human brain uses the time-lag to detect the direction. I doubt it can use amplitude, as there will be almost no difference in it.
This fact is being used in hearing aid development and construction to improve localization results for wearers. One hearing device manufacturer that I'm aware of, Unitron, has even branded a "Pinna Effect" technology that, according to their website, helps recreate the natural directionality of sound.
The location of hearing instrument microphones alters the natural sound quality enjoyed by people with normal hearing. For BTE hearing instruments, Pinna Effect recreates the natural acoustics of the ear’s pinna, providing a much more true-to-life directionality, particularly in the high frequencies. For ITE hearing instruments, Pinna Effect uses a combination of our digital shell making process and custom modeling of the location of the microphone in the ear relative to the ear drum to recreate the natural resonances of the ear.\
Our brain uses the delay between both ears, loudness, frequency, and what it "knows" about previous signals. This is called localization.