Raw media is large. Uncompressed audio stores every sample, and raw video stores every pixel of every frame. Compression exists because most of that raw data can be represented in far fewer bytes, and the craft is deciding how much of the original matters.

Lossless compression

Lossless compression guarantees exact reconstruction: the decompressed file is bit-for-bit identical to the original. FLAC for audio and PNG for images are established lossless formats. FLAC shrinks a PCM stream without discarding any of it; PNG does the same for images. Lossless formats are the natural choice when the file must be able to become the original again, such as masters and archives, but their savings are modest compared with lossy coding.

Lossy compression

Lossy compression goes further by discarding detail that human senses notice least, guided by perceptual models of how hearing and vision actually work. Audio formats such as MP3, AAC, and Opus use psychoacoustic models to drop sound masked by other sound or outside the range we perceive clearly. Image and video formats such as JPEG and H.264 use similar reasoning about vision, discarding detail in places the eye is least likely to look.

How perceptual models work

The models are built on measured limits of perception: we cannot hear all frequencies equally, and we cannot see every pixel with equal clarity. An encoder estimates which parts of the signal will be masked or unnoticed and spends its data budget on the rest. This is why lossy formats can reach a fraction of the original size while remaining, to a listener or viewer, close to indistinguishable.

The size-versus-quality trade-off

Lossy coding is a dial, not a switch. At gentler settings a lossy file is nearly transparent; at aggressive settings artifacts appear, such as warbling audio at low bitrates or blocky image edges. The right setting depends on the delivery: a small file for a quick listen online carries a different budget than an archival master. The general rule of thumb: keep a lossless master, and make lossy copies from it for delivery, so quality is never thrown away twice.