Watch real bits flow through a compressor and see where the redundancy goes. Everything runs in your browser; your data never leaves the page.
Left: original. Right: after quantisation. Move the slider to trade size for quality.
Educational model. Sizes are bit counts of simplified formats (a small header is included and described below); real file formats such as DEFLATE or JPEG add more stages.
The science
Entropy. For symbol probabilities pi, H = −Σ pi log2 pi bits/symbol is the average surprise. No lossless code can have a mean length below H (source-coding theorem).
Huffman. Repeatedly merge the two rarest symbols; code lengths li satisfy Kraft's inequality Σ 2−li ≤ 1 and H ≤ L̄ < H + 1. When all probabilities are powers of 1/2 (the "dyadic" source) L̄ = H exactly. Header cost used here: 16 bits + 13 bits per distinct symbol (a model value).
LZ77. A window of W bytes and a look-ahead of B bytes; each token is (offset, length, next byte) and costs ⌈log2 W⌉ + ⌈log2 B⌉ + 8 bits. LZW grows a dictionary (max 4096 entries) and emits codes of max(9, ⌈log2 |D|⌉) bits. RLE stores (byte, run) pairs at 16 bits per run.
Lossy. Each 8×8 block is transformed with the 2-D DCT, coefficients are divided by s·Q0 (standard luminance table scaled by the quality factor s) and rounded; size is the Huffman-coded quantised stream. PSNR = 10 log10(2552/MSE) dB.
Rate–distortion. For a Gaussian source with variance σ2 the best possible rate at distortion D is R(D) = ½ log2(σ2/D). A uniform quantiser with entropy coding sits about ½ log2(2πe/12) ≈ 0.254 bit above it; the page measures this on 200,000 samples.
Why random data does not compress. Its entropy already equals the symbol width (8 bit/byte), so there is no redundancy to remove; the headers make the result slightly larger. Kolmogorov complexity states the same idea without probabilities but cannot be computed.
Honest simplifications. No full DEFLATE or JPEG; no arithmetic coder (ideal arithmetic coding would approach H + ~2 bits total); greedy LZ77 parsing; image limited to 64×64 greyscale; input limited to 16 KB; the codec step counts are not timings. Sources: information-theory textbooks (Shannon 1948, Cover & Thomas), the DEFLATE and JPEG standards (by type). See also the Huffman and LZ77 pages of this site.
Models built with Blender (compressor frame, glass, blocks, floor) and rendered with Three.js. Not affiliated with any codec or company.