Why does compressed audio sound so horrible?

We've all heard a really poorly compressed sound file at some point in our lives. Whether it be at a school talent show, a poor quality download from Limewire, or just your friend who gave you a really small USB flash drive filled with MP3 files on it, we've all heard the awful sound of ultra-compressed digital audio. Many people think that these low-quality music tracks were a thing of the past, but in our modern age of cell phones, streaming services, and HD video in your hand, we still somehow encounter these shrill and collapsed sounding audio tracks.
But why? Why do we still encounter these problems, and what makes it sound so bad in the first place? Why does it sound like the music is being played into a bubble that's about ready to burst but can't quite make it past the threshold it needs to explode? Well, actually it's pretty simple: Because the tacks are recorded with a lower sample-rate or encoded with a lower bit rate, and that leaves out some detail. Well, actually it's a bit more complicated than that, but I'll get into it. But, what even is sample rate? What about bit rate? Why do they matter? What sample rate should I be using? What bit rate should I use? Why do some tracks even use a lower sample rate or bit rate? Well, keep reading because I will explain all that and more. Please be warned, this does actually get a bit technical, so when I get to the technical parts I'll link you to external sources that may explain what I'm talking about a little bit better.

I need a refresher, what does this compressed audio sound like?

Allow me to demonstrate. I will link two different samples of audio down below. Sample 1 is recorded at a bit rate of 32kbps, and sample 2 is recorded at 16kbps. See if you can spot the difference. Click on the music notes button to hear each sample, and click it again to stop.

As you can see, these are the same track, but the second one sounds much worse than the first. In fact, you can hear that there's significantly less detail in the higher-pitched parts of the second track in all of these examples.

But why does this happen? Why exactly do these samples sound bad? Well, it's all in the nature of digital audio and how it works. Allow me to explain...

How does digital audio work?

If you know

To explain bit rate, I first have to explain how digital

Well, if it sounds worse why would anyone use a lower bit rate? It's actually quite simple: File size. The lower-quality tracks are each smaller than their higher quality counterparts. For the first track, the 44.1KHz track is 462KB, and the 22.05KHz track is only 231KB. As you can see, by cutting the sample rate in half, we also halve the file size. (These tracks were compressed using LAME to MP3 files in order to save on bandwidth, but the original uncompressed tracks also exhibit the same file size difference).

Digital audio recording is actually a fairly new technology. In fact, the first Compact Disc players were only released onto the market in 1982. We all agree that the audio that comes from a Compact Disc actually sounds pretty good. Everyone agrees that it's at least better than cassette tapes even with Dolby noise reduction turned on, and some people even say that it sounds better than vinyl records. But getting all that sound on a disc that small is actually quite challenging. We all know that a CD holds 74 minutes of audio, but how do they get that data onto the disc? Well, it's actually really complicated.