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

What is File Compression?

How compression works

Compression finds what's predictable in data and writes it down more briefly. Lossless methods give back every byte; lossy ones, used for photos, sound and video, throw away what you won't notice. Type below or pick a sample: each method runs on it now, in your browser.

SampleEnglish proseJSON recordsServer logDNA (4 letters)Random textOne letter repeated
characters651
bytes651
byte values used33 of 256
entropy4.15 bits/byte
Original651 B · 100%
UTF-8 bytes, 8 bits per byte.
Run-length (RLE)1.25 KB · 196%
Writes "count, value" for each run of the same byte. Great for long runs, worse than nothing on normal text.
Huffman (per byte)340 B · 52%
Gives common bytes shorter codes (up to 9 bits here). Ignores order, so it can’t beat the entropy line below.
Entropy limit (per byte)338 B · 52%
4.145 bits per byte across 33 different byte values: the best any method can do if it looks at bytes one at a time.
Deflate (LZ77 + Huffman)345 B · 53%
Replaces repeats with pointers, then Huffman-codes the result. ZIP, PNG and gzip all use it.
gzip file363 B · 56%
Deflate plus an 18-byte header and checksum.
Deflate saved 47%, but didn’t reach the per-byte limit: on short or varied text, the cost of describing its codes takes a bigger share.

The trick behind ZIP, PNG and gzip: copy what came before

LZ77 walks through the text and, whenever the next few characters already appeared, writes "go back d, copy l" instead. Highlighted characters below are copies; plain ones are written out. Hover a highlight to see its instruction.

written out295 chars
copied356 chars
copy share55%
A file is a long row of numbers. Compression looks for patterns in that row and describes them more briefly than the row itself. Text has many patterns: some letters are far more common than others, and whole words repeat. A compressor that knows "e" is common can give it a short code; one that remembers what came before can replace a repeated phrase with a pointer back to its first appearance. The more a file repeats itself, the smaller it gets. A file that never repeats, like the output of a good random number generator or a file that is already compressed, has nothing left to describe more briefly, and stays the same size or grows a little.

Why you can't compress forever

A good compressor's output looks random, and random data has nothing left to predict. Compress the result again and it gets slightly bigger, because the container adds a header and bookkeeping. There are more possible files of n bytes than of n − 1 bytes, so no method can shrink every input; some must grow.

Original651 Byour text
Compressed once363 Bgzip
Compressed again386 B+23 bytes vs once

The methods, and where you meet them

methodyearideaused in
Huffman coding1952Short codes for common symbols, long for rare ones, built from symbol counts.Inside JPEG, PNG, ZIP, MP3
Run-length1960sStore "how many, of what" for repeated runs.Fax machines, BMP RLE, TIFF PackBits
LZ771977Point back to an earlier copy of the same bytes.Base of Deflate, LZMA, Brotli, Zstandard
LZW1984Build a dictionary of strings as you go.GIF, early TIFF, Unix compress
Arithmetic coding1979Encode the whole message as one number; beats Huffman’s whole-bit codes.JPEG 2000, H.264 CABAC, AV1
Deflate1993LZ77 then Huffman, in blocks.ZIP, gzip, PNG, DOCX, PDF streams
bzip21996Reorder text with the Burrows: Wheeler transform so similar letters sit together..tar.bz2 archives
LZMA1998LZ77 with a huge window and range coding.7-Zip, .xz
Brotli2015LZ77 + context modelling + a built-in web dictionary.HTTP Content-Encoding: br, WOFF2
Zstandard2016LZ77 + fast entropy coding, tunable from very fast to very small.Linux packages, databases, HTTP zstd

Frequently Asked Questions

Is compression always lossless?

No. Lossless compression (ZIP, PNG, FLAC) perfectly preserves all data. Lossy compression (JPEG, MP3, H.264) permanently removes some data to achieve higher compression ratios.

How much can compression reduce file size?

It varies hugely. Text files can compress to 10% of original size. Already-compressed files (JPEGs, MP3s) may only reduce by 1-5%.

Does compression reduce quality?

Lossless compression does not affect quality. Lossy compression reduces quality, but modern algorithms make the loss nearly imperceptible at reasonable settings.

What is the best compression format?

For documents: ZIP or 7Z. For images: WebP or AVIF. For audio: AAC or OGG. For video: H.264 or H.265.

Why are some files already compressed?

JPEG, MP3, MP4, and ZIP files are already compressed. Trying to compress them again yields little benefit.