As an audio engineer I can try to explain this as best I can.
First, a bit of background. Almost every sound in the natural world is made up of a fundamental, or base, frequency and a series of harmonics, or overtones, which influence the tonal characteristics of a sound. We refer to this as timbre. It's what differentiates a trombone from a bird call, etc.
As your distance from the sound source changes, so does the timbre of the sound. By nature, lower sound frequencies carry more energy than higher ones, so as distance increases, higher frequencies are not able to be heard as well because they lose the energy to propagate sound waves much earlier.
Imagine someone speaking to you at a consistent loudness from varying distances. From a few inches, you hear that a whisper has very accentuated high frequencies. This is heard in the whistle of air rushing past the lips, the "smack" of the lips of the speaker, etc. As the speaker moves away, these very high frequencies have much lower amplitude. You can't hear these fine details nearly as well from even a foot away. The timbre changes.
I hope I explained this well enough. I thought it might be interesting for you to hear it from the perspective of someone in the recording industry as opposed to a more scientific field. If I need to elaborate on anything above please let me know!
Edit: I forgot two very important things that help determine the distance of a sound source:
Direct sound vs reflected sound- from a few inches, most of the sound you're hearing is direct sound, ie, it's going straight from the sound source to your ear. Further away, there is more likelihood that the sound you're hearing is indirect sound, that is, sound that has reflected off of the environment around you and made its way to your ear.
Binaural hearing- humans have two ears. Who knew! This is how humans determine everything about the position of a sound; your brain analyzes the discrepancy between the sound heard at each ear to help you determine the position of a sound. This ties in with the above blurb about direct and reflected sound. If a sound is positioned directly to the left of you, you'll hear more direct sound in your left ear and more reflected sound in your right ear. Your brain understands this, and thus determines the sound is somewhere to your left. The amount of direct sound compared to reflected sound is how your brain determines the distance to the sound source. Analyzing distance and position is how your brain figures out the location of a sound.
Edit v2: finally, my audio nerd lectures are useful outside of the recording studio! I'm glad you guys found it interesting.
One important source of distance cues is reflections. In everyday situations, a lot of the sound reaching our ears has bounced off of walls, buildings, furniture, etc. This is easy to notice in, say, a concrete parking garage, but it's also playing a big role in environments where it's not so obvious, like a bedroom or outdoors. Try snapping or clapping in different environments and listening for the reflections that immediately trail the original sound. Anyway, this can give a lot of information about distance. If someone is speaking near to your ear, the original, unreflected sound of their voice will be much louder than the reverberations that follow, whereas if they are calling to you from down a long hallway, the reflections will be a much louder part of what you hear.
Also very important is the fact that you have two ears. You can tell the direction of a sound source by which ear it reaches first and which ear it's louder in. In combination with this, turning your head in different directions or moving it around while listening can give you quite a bit of information about the location of a sound. There are a lot of subtle things involved here; the shape of your ears imparts different frequency curves to sounds coming from different directions (behind, in front, above, below), and your brain combines all of these subtle clues together.
Additionally, as sound travels through the air, higher frequencies are filtered out more quickly than lower frequencies (both due to absorption as sound travels through air and due to the fact that lower frequencies can diffract around corners and obstacles more easily), so a distant sound will be more muffled compared to a close by sound with sharp high frequencies.
Finally, we can also often see the source of a sound with our eyes in addition to hearing it, and your brain can integrate this information with all the other spatial cues available to create a complete mental picture regarding the location of a sound.
So if you were to stand in a perfectly anechoic chamber (where the walls absorb all sound instead of reflecting it), blindfolded, with one ear perfectly plugged, and you were forbidden from moving or turning your head, it would be very difficult to distinguish a near, faint sound from a distant, loud sound.
Air absorbs higher pitches more than lower, far away things will sound deeper. Sort of like how distant objects look bluer.
Also, probably more important, sound takes multiple paths, so distant sounds are sort of smeared out. Think of the sharp crack of nearby lightning vs the rolling boom of far away.
Lots of answers about frequency drop-off over distance, but that is only really noticeable over very large distances. There's a problem with using frequency spectrum as a perception of distance in smaller spaces: you don't *know* that frequencies have dropped off unless you've heard it before at a closer distance. You need multiple instances of the same sound to compare.
There is one very big difference between close sounds and far sounds that can be heard in a single instance: the ratio of direct and reflected sound.
When a sound occurs very close to you, the direct sound wave hits your ears at near-full loudness, and the reverberation sounds quieter in comparison. If that exact same sound occurred further away, the direct sound would be quieter **but the reflected sound would stay the same loudness**. This means distant sounds are heard as less direct and more reverberant. This difference can even be heard even in small rooms.
Don't get me wrong: loudness and frequency drop-off ARE both perceptual indicators of distance. All these things work in harmony (heh). But both of them require prior knowledge, both are comparative perceptions. Direct vs reflected ratio is an *absolute* perception of distance.
) a good reference for this topic, namely absolute vs. comparative distance perception. My current PhD thesis is on Acoustics, and luckily I've already written the section on distance perception.
(PS. A similar but less powerful distancing-effect relates to early reflections off of walls, and how their angle of incidence becomes greater the further away the sound source is. But that's a whole other story.)
The reason why you can tell the distance is often due to logical assumptions based on the characteristic of the sound you heard. We can all agree that a whisper sounds different from a fire engine. If you hear a whisper you immediately know it came from close, because there's likely no such thing as a loud whisper. Take another example of how this perception isn't really standalone: movies can make one exact sound close or far from just volume, i.e. if they want to show a fire truck in the foreground or the far background.
Some other factors:
- You probably have been calibrated from experience, for example, how loud a fire truck sounds up close. And from further experience, you subconsciously quantify how much you perceive sound pressure decrease over distance and hence can infer a distance.
- There are many other characteristics of sound that can come into this. Not least of which is echo, if you hear a sound up close, there are probably no echos in the signal you hear. However, if a sound comes from far, it is likely that echos and muffled parts are also bouncing around and a component of those sound waves that you hear and hence you can infer they came from far away.
- Take into consideration also the fact that different frequency components in sound waves travel at different speeds (in fact this is a property of a medium called dispersion) and a far fire engine sounds distinctly different from a close one.
- There may be many other physical phenomenon that contribute to this perception, though these are the ones I could think of.
There are two major strategies we’ve evolved:
Interaural Time Difference (ITD) - time between the arrival of a sound at either ear (works well for lower frequencies)
Interaural Level Difference (ILD) - difference in magnitude of sound between ears (works well for higher frequencies)
Consider the cases you specified:
Loud and far — low ITD, high ILD
Close and quiet — high ITD, low ILD
The cochlea stuff that other people have mentioned relates to how your brain distinguishes pitch, but it’s really the difference in sound time / magnitude which matters for your question.