Data Compression
Representing data in fewer bits by exploiting its patterns, either exactly (lossless) or by discarding what people won't notice (lossy), with limits set by information theory.
Data compression encodes information in fewer bits than the original by exploiting patterns and redundancy. There are two kinds:
- Lossless compression reconstructs the original exactly. It's required for text, code, and anything where a single changed bit matters. ZIP, gzip, PNG, and FLAC are lossless.
- Lossy compression discards information people are unlikely to notice, achieving much smaller sizes. JPEG, MP3, and modern video codecs are lossy.
The theoretical limit comes from Claude Shannon's 1948 paper founding information theory. Shannon defined the entropy of a source as the average information per symbol, measured in bits, and proved no lossless code can beat it on average. Predictable data has low entropy and compresses well; random data has maximal entropy and can't be compressed at all. A simple counting argument shows no lossless method can shrink every input: there are fewer short files than long ones, so some inputs must get longer. The term borrows from thermodynamic Entropy, and the two are mathematically related.
Two classic techniques underlie most lossless formats:
- Huffman coding. Invented by David Huffman in 1952. Common symbols get short codes and rare ones get long codes, built from a tree so no code is the prefix of another.
- Dictionary methods. Abraham Lempel and Jacob Ziv's LZ77 (1977) replaces repeated sequences with references back to earlier occurrences: "copy 12 bytes from 40 bytes ago." Text and code are full of repetition, so this works well.
DEFLATE, behind gzip, ZIP, and PNG, combines both. Newer formats such as Brotli and Zstandard use larger windows, better modeling, and built-in dictionaries for faster or smaller results.
Lossy compression relies on models of perception. JPEG transforms each block of pixels into frequencies and stores high frequencies, fine detail the eye barely notices, with less precision. Audio codecs drop sounds masked by louder ones nearby. Reducing numeric precision in this way is a kind of Quantization, the idea used to shrink machine learning models.
Compression is everywhere on the web. Servers compress text responses, often cutting them by 70 percent or more, which speeds up the Critical Rendering Path. HTTP/2 and HTTP/3 compress headers, and choosing modern image formats is a large part of Responsive Images. Databases gain hugely from Columnar Storage, where values of one type sit together and compress far better than mixed rows. Language models split text into tokens using Byte-Pair Encoding, originally a compression technique.
There is a deep link between compression and prediction: a model that predicts the next symbol well can compress well, and vice versa. Kolmogorov complexity, the length of the shortest program that produces a given output, is the ultimate measure of compressibility, but it is uncomputable, a consequence of the halting problem.
See also3
Git Object Model
Git stores every version of a project as a graph of immutable objects named by the hashes of their contents, blobs for files, trees for directories, and commits for snapshots, which makes history tamper-evident and identical content free to store twice.
Version Control & Delivery12 connections
Image Format
The file formats the web uses for pictures, from the GIF, JPEG, and PNG generation to newer formats derived from video codecs, and the slow, politics-laden process by which a new one becomes safe to use.
Web Platform9 connections
Archive File
Files that bundle many files and their metadata into one, from tape-era tar streams to zip's index at the end, whose design choices still decide what can be listed, extracted, or exploited.
Systems & Tooling6 connections
Linked from11
- Archive FileSystems & Tooling
Files that bundle many files and their metadata into one, from tape-era tar streams to zip's index at the end, whose design choices still decide what can be listed, extracted, or exploited.
- BandwidthNetworks & Distribution
How much data a link can carry per second, why that's different from how fast it feels, and why a fast connection can still be slow for small requests.
- BluetoothNetworks & Distribution
Short-range radio for connecting nearby devices such as headphones, keyboards, and sensors, which hops frequencies to dodge interference and comes in a classic and a low-energy flavor.
- Byte-Pair EncodingAgents & Language Models
The compression trick that splits text into the tokens a language model reads, by repeatedly merging the most frequent pair of symbols into a new one.
- EntropyMatter & Energy
The measure of how many ways a system's parts can be arranged without changing how it looks, which always grows in total and gives time its direction.
- GIFGraphics & Rendering
A 1987 image format limited to 256 colors per frame that survived a patent fight, the rise of better formats, and its own inefficiency to become the internet's format for short looping clips and reactions.
- Git Object ModelVersion Control & Delivery
Git stores every version of a project as a graph of immutable objects named by the hashes of their contents, blobs for files, trees for directories, and commits for snapshots, which makes history tamper-evident and identical content free to store twice.
- HTTP2 and HTTP3Web Platform
Two successive rewrites of HTTP's transport layer, each solving the previous version's head-of-line blocking at a different layer.
- Image FormatWeb Platform
The file formats the web uses for pictures, from the GIF, JPEG, and PNG generation to newer formats derived from video codecs, and the slow, politics-laden process by which a new one becomes safe to use.
- JPEGGraphics & Rendering
The dominant photo format since 1992, which shrinks images about tenfold by converting 8×8 blocks into frequency patterns and rounding away the fine detail the eye barely notices.
- Text-to-SpeechAgents & Language Models
Turning text into spoken audio, from robotic formant synthesizers to neural voices that clone a speaker from seconds of audio, and the latency and consent questions that come with them.