The brain is an excellent computer, and there are inherent programs biologically engineered. For the analogous reason that one needs at least two loud speakers to get stereophonic sound, two ears are necessary for localization. At my old age, when one ear's hearing has diminished more with respect to the other's, I have trouble localizing sounds.
This description of the processing makes it clearer:
The localization of sound is an essential part of natural binaural hearing. But how can our brain exactly pinpoint a sound source?
Due to disturbances in the air, sound travels in waves. This is why a sound closer to one ear reaches this ear a bit louder and slightly ahead of the other ear. By combining the different information on time and loudness from both ears, our brain can precisely pinpoint a sound source. This makes natural binaural hearing especially helpful for orientation in noisy environments like traffic situations
This goes into analysis, from the abstract:
An essential task for the central auditory pathways is to parse the au-
ditory messages sent by the two cochleae into auditory objects, the
segregation and localisation of which constitute an important means
of separating target signals from noise and competing sources. When
hearing losses are too asymmetric, the patients face a situation in
which the monaural exploitation of sound messages significantly
lessens their performance compared to what it should be in a binaural
It is worth reading the article in wikipedia which also has diagrams. There are several biophysical models utilizing the distinct variables of sound arrival, the physics entering the input parameters of sound, the biology the receptors of the body. There are enough parameters to constrain the various models .
The sound localization mechanisms of the mammalian auditory system have been extensively studied. The auditory system uses several cues for sound source localization, including time- and level-differences (or intensity-difference) between both ears, spectral information, timing analysis, correlation analysis, and pattern matching.
Suppose a sound is produced behind you. You can easily tell that the sound came from behind.
Our ear lobes face towards the front and hence traps the sound waves which come from the front. Yet, we can detect that the sound came from behind.
Here is a drawing of an earlobe:
Notice the curling bits? The ones on the top right catch the sound coming from behind. The sound waves are not trapped, they are amplified , the way a palm behind your ear enhances the sounds. And the brain's computer is good enough to fit all the parameters arriving on the ears , frequency, amplitude, angular direction to locate the source direction.
We can claim that the sound which was produced behind the person was reflected by some object to enter the ear but now the new question is how does the ear know if the sound was refelected by that object or if the sound was produced by the object?
The primary source for the brain are the reflections from the earlobes in order to build a stereo image of sound sources. That is the function of all those curls. Reflections are secondary data, and can be confused with primary sources, echoes for example . A cat gets the same location functionality by turning around its ears, as they only gather sound waves in a cone.
Or in general, how does the ear identify the location of the source?
By having an inbuilt program which solves for the parameters coming from the ear, as explained in the various links.
This article might be of interest.