Lossless Compression
A compression method that reduces file size without discarding any data — the original file is reconstructed exactly from the compressed version.
Last updated
What Is Lossless Compression?
Lossless compression is a data compression technique that reduces file size by encoding redundant patterns more efficiently — without discarding any information. Decompressing a losslessly compressed file produces a bit-for-bit identical copy of the original.
How It Works
Lossless algorithms identify and exploit patterns in data:
Run-length encoding (RLE): Replaces repeated values with a count. "AAAAAAABBB" → "7A3B". Efficient for simple graphics with large flat-colour areas.
Dictionary-based encoding (LZ77, DEFLATE): Identifies repeated sequences of bytes and replaces later occurrences with references to earlier ones. Used by ZIP, PNG, and gzip.
Entropy coding (Huffman, Arithmetic): Assigns shorter bit sequences to more frequent symbols. The most common byte value gets the shortest code.
Formats That Use Lossless Compression
| Format | Algorithm | Use Case |
|---|---|---|
| PNG | DEFLATE | Images with flat colours, text, logos |
| ZIP | DEFLATE | General file archives |
| FLAC | Linear prediction + entropy coding | Audio |
| WebP lossless | LZ77 variant | Web images |
| TIFF (LZW) | LZW | Professional image archival |
| PDF (internally) | DEFLATE for text streams | Document text |
Lossless vs Lossy: When to Choose
| Choose Lossless When | Choose Lossy When |
|---|---|
| The file will be edited again | File is a final delivery asset |
| Pixel-perfect accuracy is required | File size reduction is the priority |
| The file is a working copy | Slight quality loss is acceptable |
| Content is graphics, text, or code | Content is a photograph or video |