Technology

Lossy vs Lossless Compression: What Actually Changes in the File?

Learn the difference between lossy and lossless compression, how each method works, what data is removed, and when to use one over the other.

Lossy vs Lossless Compression: What Actually Changes in the File?

Almost everyone has encountered the terms lossy compression and lossless compression. You might see them when:

  • Exporting images
  • Compressing PDFs
  • Encoding audio
  • Optimising videos
  • Saving design files

The names suggest a simple difference: lossless means nothing is lost, lossy means something is lost. While technically correct, that explanation doesn’t really answer the question most people are asking:

What actually changes inside the file?

Understanding that distinction helps explain why some files can shrink dramatically while others only become slightly smaller.

Why Compression Exists

Digital files contain a lot of data: a single image might contain millions of pixels, a video might contain billions, and an audio recording may contain tens of thousands of samples every second.

Without compression, file sizes would quickly become impractical. Compression attempts to reduce file size while preserving as much useful information as possible, and different compression methods achieve this in different ways. This is where lossy and lossless compression diverge.

What Is Lossless Compression?

Lossless compression reduces file size without permanently removing information. After decompression, the original file can be reconstructed exactly: every bit of data remains intact.

Original File

Lossless Compression

Compressed File

Decompression

Original File

The final result is identical to the starting file. Nothing is discarded.

How Lossless Compression Works

Lossless compression looks for redundancy. A file might contain:

AAAAAAAAAA

Instead of storing:

AAAAAAAAAA

the compression algorithm may store:

10 × A

The same information requires less space, and when decompressed, the original data is restored perfectly.

Real compression algorithms are far more sophisticated, but the principle remains similar: they identify patterns, repetition, and predictable structures that can be represented more efficiently.

It’s worth distinguishing this from encoding schemes like Base64 versus hex encoding, which change how data is represented without actually reducing its size, and sometimes increase it.

Common Lossless Formats

Lossless compression is used in many popular formats.

Images

  • PNG
  • GIF
  • TIFF (optional)
  • RAW formats

PNG in particular is often discussed alongside vector formats; see SVG versus PNG for how a lossless raster format compares to a format that doesn’t rely on pixel compression at all.

Audio

  • FLAC
  • ALAC
  • WAV (typically uncompressed)

Archives

  • ZIP
  • 7Z
  • GZIP
  • RAR

Many archive formats also embed checksums so the decompressed data can be verified as byte-for-byte correct.

Documents

  • Many PDF files
  • Office document formats such as DOCX and XLSX

These formats preserve the original data.

What Is Lossy Compression?

Lossy compression reduces file size by permanently removing information. The algorithm decides which data is less important and discards it.

Original File

Lossy Compression

Smaller File

Once removed, that information cannot be recovered. Even if the file is decompressed later, the original file no longer exists.

Why Lossy Compression Exists

If lossless compression preserves everything, why use lossy compression at all? Because some files contain enormous amounts of information. Lossless compression can only remove redundancy, while lossy compression can remove actual content. This allows much larger size reductions.

Consider:

  • A 20 MB image becoming 3 MB
  • A 100 MB audio file becoming 8 MB
  • A 1 GB video becoming 100 MB

These reductions would often be impossible using lossless methods alone. For a broader look at how different image formats handle this trade-off, see the MDN image file type guide.

How Lossy Compression Works

Lossy compression relies on a key observation: humans do not perceive all information equally. Some details contribute significantly to perception, others contribute very little. Compression algorithms attempt to remove information that people are less likely to notice. The exact approach depends on the file type.

Lossy Image Compression

Image formats such as JPEG analyse visual information. The algorithm may:

  • Remove subtle colour variations
  • Simplify fine detail
  • Reduce high-frequency information
  • Approximate neighbouring pixels

The image still looks similar, but the underlying pixel data changes. This kind of compression is only really relevant to raster images in the first place; see vector versus raster images for why vector formats don’t face the same trade-off.

This is why repeatedly saving a JPEG often causes visible quality degradation: each save removes additional information.

Lossy Audio Compression

Formats such as MP3 and AAC use psychoacoustic models that attempt to remove sounds that are less noticeable to human hearing. Examples include:

  • Frequencies outside typical hearing ranges
  • Sounds masked by louder frequencies
  • Very subtle audio details

The listener often perceives little difference while file size decreases dramatically.

Lossy Video Compression

Video compression combines multiple techniques. Algorithms may:

  • Remove visual detail
  • Simplify colour information
  • Predict motion between frames
  • Store only differences between frames

Modern video formats such as H.264 and H.265 depend heavily on lossy compression, and without it, streaming services would be impractical.

What Actually Changes in the File?

This is the most important distinction.

Lossless Compression

The data remains identical.

Original Data
=
Recovered Data

Every bit can be restored.

Lossy Compression

The data changes.

Original Data

Recovered Data

The file may appear similar, but portions of the original information no longer exist. The degree of change depends on compression settings.

Lossy vs Lossless Compression

FeatureLosslessLossy
Original Data PreservedYesNo
Quality ReductionNonePossible
File Size ReductionModerateSignificant
ReversibleYesNo
Repeated Saves SafeYesNo
Suitable for EditingExcellentLimited
Suitable for DistributionSometimesOften

Neither approach is universally better: the right choice depends on the use case.

Why PNG Files Are Larger Than JPEG Files

This comparison illustrates the difference perfectly. PNG uses lossless compression, while JPEG uses lossy compression.

A photograph containing millions of colours, fine gradients, and complex textures illustrates the difference well. PNG must preserve every pixel exactly, while JPEG can simplify some of that information. The result:

PNG = Larger File
JPEG = Smaller File

This is why photographs are usually saved as JPEG while logos and screenshots are often saved as PNG. For the formal specification behind PNG’s lossless approach, see the W3C PNG specification.

Why PDFs Sometimes Shrink Dramatically

PDF compression depends on the content inside the document.

A PDF containing:

  • Text
  • Vector graphics

may already be relatively efficient.

A PDF containing:

  • High-resolution images
  • Scanned pages

often benefits significantly from lossy image compression.

Many PDF compression tools reduce size by recompressing embedded images rather than modifying the document structure itself.

Why Repeated JPEG Saves Reduce Quality

A common misconception is that saving a JPEG simply preserves the existing file. What actually happens is:

JPEG

Decompress

Recompress

Each recompression step removes additional information, and over time, visible artifacts begin to appear. These may include:

  • Blurring
  • Blockiness
  • Colour degradation
  • Loss of fine detail

Lossless formats do not suffer from this problem.

When Should You Use Lossless Compression?

Lossless compression is usually the best choice when:

  • Editing files repeatedly
  • Preserving original quality
  • Storing source material
  • Archiving important data
  • Working with graphics containing text

Examples include:

  • Design assets
  • Source photographs
  • Software files
  • Legal documents
  • Database backups

When Should You Use Lossy Compression?

Lossy compression is often appropriate when:

  • Minimising file size matters
  • Small quality reductions are acceptable
  • Files are being distributed rather than edited
  • Bandwidth is limited

Examples include:

  • Website images
  • Streaming video
  • Music distribution
  • Email attachments
  • Social media uploads

Can Lossy Compression Be Invisible?

Yes. At high quality settings, differences may be impossible to detect without specialised analysis. This is why many users cannot distinguish between:

  • Original photographs
  • High-quality JPEGs

or

  • CD-quality audio
  • High-bitrate MP3 files

The data has changed, but human perception may not notice.

The Biggest Compression Myth

A common misconception is:

Lossless = Better

This isn’t always true. A 50 MB PNG may technically preserve more information than a 4 MB JPEG, but if viewers cannot perceive the difference, the larger file may offer little practical benefit. The best compression method depends on the purpose of the file.

FAQ

Why does my JPEG get worse every time I save it? Each time you open and resave a JPEG, it gets decompressed and recompressed, and that recompression step removes additional information. Over enough save cycles, this shows up as blurring, blockiness, or colour degradation. Editing in a lossless format and only exporting to JPEG once avoids this.

Is lossless always better than lossy? Not in practice. Lossless preserves every bit of the original data, but if a lossy version is visually or audibly indistinguishable at a fraction of the file size, the extra data in the lossless file often has little practical value, especially for distribution rather than editing.

Can converting a lossy file back to a lossless format restore the lost data? No. Once lossy compression discards information, it’s gone. Saving a compressed JPEG as a PNG will preserve whatever pixel data remains at that point, but it won’t recover the detail that was already removed.

Can you tell the difference between lossy and lossless just by looking at a file? Not reliably, especially at high quality settings. A well-compressed lossy file can look identical to the original to the naked eye, even though the underlying data has changed. Specialised analysis or a direct pixel/waveform comparison is usually needed to detect the difference.

Which should I use for archiving important files? Lossless. Archives, source photographs, legal documents, and anything you might need to edit or reference exactly later should stay in a lossless format so no information is permanently discarded.

Conclusion

Lossless compression reduces file size by finding more efficient ways to store existing information. Every bit of the original data remains intact and can be recovered perfectly.

Lossy compression reduces file size by permanently removing information that the algorithm considers less important. The resulting file is smaller, but portions of the original data are gone forever.

The key difference is not whether the file looks the same. It is whether the underlying data remains identical. Lossless compression preserves it. Lossy compression changes it.

Understanding that distinction makes it easier to choose the right format for images, audio, video, PDFs, and almost every other type of digital file.

Written by the Workshelve team, who write practical explainers on data integrity, networking, and developer tooling.

Top