Why does sound attenuate in air differently in different situations? Sound attenuates in air, and some frequencies go quieter quicker than others. But it feels like which frequencies get quieter should be consistent. Here's two opposing examples:


*

*At a party, there's loud music with a reasonably flat frequency response. When I go outside, away from the party, only the bass notes are heard. So air must be like a low-pass filter.

*My headphones have a reasonably flat frequency response when I have them on, but when I take them off, all the bass notes disappear. So air must be like a high-pass filter...?
What does air actually do, and what actually happens in these two situations?
 A: You are right that air works like a low-pass filter. While David's comment about walls also blocking high frequencies is entirely correct and probably the dominant effect in your case, you would also be able to hear this effect at an outdoor party on a flat plain.
The main reason for the attenuation of audible frequencies is not that straightforward to explain, since it is rooted in quantum statistical mechanics. (It comes from equilibration of energy between the air molecules' vibrational energy and their translational energy, which comes from how fast the molecules tend to move.) In the end, though, we get a humidity-dependent attenuation that looks something like this:

You can find the equations underlying this figure here. This is also explained in more detail in many good textbooks on physical acoustics, such as Fundamentals of Acoustics by Kinsler et al. (2000) or Fundamentals of Physical Acoustics by Blackstock (2000).
(In the example of a party on a flat plain, you would also get a significant attenuation of the sound because of the interaction between the sound wave and the ground, especially if it is an acoustically soft material like fresh snow.)
I don't have enough knowledge to answer your second example as well, but I am sure that it is not due to attenuation in air. My first guess was that it might be caused by the proximity effect, where bass frequencies are boosted in microphones (and probably also eardrums) when they are close to the sound source.
However, according to this article and these Reddit comments, the real reason is that the headphones nearly enclose your ear channel, which causes the headphone speaker to be well coupled to your eardrum. This fits well with my own personal experience, where pushing my earbuds slightly further in to seal the ear canal better can have a big impact on the bass response. Pulling headphones ever so slightly off my ears also reduces the bass response by a lot.
