fileformer
search⌘KtranslateENexpand_moreupload_fileConvert
Converters8 file families · 44 direct conversions
What changes in a conversionarrow_forward
concepts / lossless compression

What is Lossless Compression?

Smaller, and every bit comes back.

Lossless compression only removes repetition and predictability, so unpacking gives back the exact original. Here your browser packs a file, unpacks it, and proves it with a SHA-256 fingerprint of both ends.

Server logJSON exportRaw pixelsRandom bytesgzipdeflatedeflate-raw
descriptionOriginal115,890 bytes
115.9 kB
FIRST 16 BYTES31 30 2e 30 2e 30 2e 31 32 20 2d 20 2d 20 5b 32
SHA-2566f398e5b8c79852fdad375353aa133d1d51eef1f4474f432acfc3c10dc83100f
compressPacked (gzip)in 82.7 ms
11.8 kB
FIRST 16 BYTES1f 8b 08 00 00 00 00 00 00 0a 9d 7d 4d af 45 bb
SHA-2560ffde7a7ed1a4969f623c65c614d2d4cfdc4ea67b4939d015c84dd2e3e2c4d33
expandUnpackedin 35.7 ms
115.9 kB
FIRST 16 BYTES31 30 2e 30 2e 30 2e 31 32 20 2d 20 2d 20 5b 32
SHA-2566f398e5b8c79852fdad375353aa133d1d51eef1f4474f432acfc3c10dc83100f
verifiedIdentical: all 115,890 bytes, same fingerprintThe packed copy is 10.2% of the original, 9.8× smaller. The fingerprints at both ends match, which a single changed bit would break.

Guess the next pixel, store only the surprise.

PNG doesn't compress pixels directly. Each row is first rewritten as the difference from a guess: the pixel to the left, the one above, their average, or Paeth's pick of the three. Good guesses leave mostly zeros, and zeros compress well. These are the five real PNG filters run on a test image, then packed with the same DEFLATE that PNG uses.

PhotoScreenshotLine drawingfiltering and packing…
THE IMAGE
WHAT PAETH STORES (GREY = 0)
HOW OFTEN EACH STORED VALUE APPEARS (−64 TO +64)…
filter (guess)zerosentropyDEFLATE
Nonestore the pixel………
Subguess = left………
Upguess = above………
Averageguess = (left + above) / 2………
Paethclosest of left, above, corner………
Adaptivebest filter per row………

Running all five filters…

Why FLAC beats ZIP on music.

A general compressor looks for repeated byte strings, and recorded sound almost never repeats exactly. FLAC instead predicts each sample from the last few, using the fixed polynomial predictors in its specification, and stores the error with a Rice code. This runs both on one second of generated 16-bit sound.

Plucked noteVoice-likeWhite noise
SAMPLES 8,000-8,600 · ERROR OF FIXED ORDER 2
soundprediction error (stored)
methodbits / samplesize vs WAV
WAV, 16-bitno compression16.00100%
gzip on the byteswhat a ZIP would do15.2595%
FLAC fixed order 0guess 014.8293%
FLAC fixed order 1guess = last sample9.9462%
FLAC fixed order 2continue the slope5.6635%
FLAC fixed order 3continue the curve3.2520%
FLAC fixed order 4four-sample curve3.6123%

The best predictor here, order 3, needs 3.25 bits per sample, 4.9× smaller than WAV, while gzip only reaches 15.25. Real FLAC encoders also try longer custom predictors and stereo tricks, and keep whichever is smallest for each block. Rice coding here uses the best parameter per 4,096-sample block.

How each lossless format finds its savings

formatstep 1: model or predictstep 2: store compactlyspecification
PNGimageOne of five filters per row (None, Sub, Up, Average, Paeth), as in the lab aboveDEFLATE: LZ77 back-references plus Huffman codesW3C PNG 3rd ed.
WebP losslessimage14 spatial predictors chosen per block, colour transform, colour cache of recent pixelsLZ77 with 2-D distance codes, HuffmanRFC 9649
JPEG XL (lossless)imageSelf-correcting weighted predictor; can also repack an existing JPEG exactly, about 20% smallerANS entropy coding with context modellingISO/IEC 18181
FLACaudioFixed predictors of order 0-4 or LPC up to order 32 per block; left/right or mid/side stereoRice codes on the prediction errorRFC 9639
ALACaudioAdaptive linear prediction per frame, channel decorrelationAdaptive Golomb: Rice codesApple open source, 2011
FFV1videoMedian prediction from left, above and their gradient, per planeRange coder with context statesRFC 9043
ZIP / gzip (DEFLATE)archiveNo prediction: finds repeated strings up to 32 KB backHuffman codes for literals, lengths and distancesRFC 1951 / 1952
ZstandardarchiveRepeated strings with a much larger window, optional trained dictionaryFinite State Entropy (tANS) and HuffmanRFC 8878
BrotliarchiveRepeated strings plus a built-in dictionary of common web textContext-modelled Huffman codesRFC 7932
7z / xz (LZMA2)archiveRepeated strings, window up to 1.5 GB in 7-ZipBinary range coder with bit-level context models7-Zip / xz docs

Frequently Asked Questions

What is the difference between lossless and lossy compression?

Lossless: no data lost, perfect reconstruction, larger files. Lossy: data permanently discarded, smaller files, slight quality reduction.

Is PNG lossless?

Yes, PNG is always lossless. Every pixel is perfectly preserved when saving as PNG, unlike JPEG.

Is ZIP lossless?

Yes, ZIP is always lossless. Files inside a ZIP archive are exactly identical to the originals when extracted.

Should I use lossless for photos?

For archiving or editing: use lossless (PNG or TIFF). For web sharing: JPEG or WebP lossy is fine as they look almost identical at good settings.

What is the best lossless audio format?

FLAC is the most popular lossless audio format. WAV and AIFF are also lossless but larger. Apple ALAC is Apple's lossless format.