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.