system
Given the following post, respond as if you're commenting on Reddit:
human
What exactly is happening when I convert a  file from .wav to mp3(or any other type of file converting really)?
gpt
.mp3 and .wav are both file formats.  They are separate, incompatible formats, each with header data describing the particulars of the rest of the data.  In .wav's case, it can contain a variety of audio formats, but is most typically used with some sort of uncompressed digital audio.  In the case of MP3, it contains compressed digital audio.

The compression for MP3 is a lossy form of compression.  When you compress audio into the format for an MP3 file, you lose precision, that cannot be recovered when the file is decompressed.  This is why it is referred to as lossy compression.

Firstly, the digital audio is divided up into semi-overlapping frames, each frame very short in duration.  For each frame, an algorithm called a "modified discrete cosine transform" translates digital audio samples from time-based samples (amplitude vs time) into frequency-based coefficients, where instead of each sample representing a specific point in time, each one represents a certain frequency at a certain phase.

Up to this point, no space has been saved.  The space saving comes from the quantization step.  Quantization is where you reduce the precision of numerical values by a certain amount.  Think of it as dividing your real values by a certain number, and discarding the remainder.  The remaining number is smaller, and due to discarding the remainder, has less precision.  It can later be restored to a value approximating the former value, but the exact precision has been lost.  Since the remaining number is smaller, it also requires less bits to represent its value, hence the compression.  A variable length encoding of some sort is then run over the coefficients, where the fewer bits of precision a value has, the less space it takes up.

The encoding of an MP3 follows this basic principle, but it is a lot more complicated, because the encoder has several choices to make.  The encoder needs to vary the quantizer (ie, the amount by which precision is reduced) in order to result in the best compression, but also to have the minimum impact on sound quality.  Therefore, frequencies which are less likely to be noticed will have a higher quantizer.  It can make dynamic decisions, where a loud noise in one frequency may, in the listener's mind, mask detail in nearby frequencies almost completely, allowing the encoder to spend very few bits on those masked frequencies.  This is called psychoacoustics.

The MP3 format defines how the data is stored and how it is decompressed, but it is up to the various codecs to decide how best to compress, so not all codecs will be equal to others.  They will all be bound by the specification of the file they are allowed to produce, but the better ones have years of psychoacoustic modelling behind them, improving them.