Under the hood

Compression is prediction.

A JPEG, a zipped brainwave recording and a large language model are doing the same job. Each one guesses what comes next and stores only the part it got wrong. The better the guess, the smaller the file. This page shows the idea with real numbers, computed in your browser. Nothing is uploaded.

1

Predict

Guess the next thing from what came before: the next pixel from its neighbours, the next EEG sample from the last two, the next word from the sentence so far.

2

Keep the surprise

Store only the gap between the guess and the truth. A good guess leaves small numbers, and small numbers are cheap to store.

3

Decide what you can lose

Lossless formats keep every bit. Lossy formats (JPEG, AVIF, MP3) quantise: they throw away detail your eye or ear will not miss.

4

Code it

Entropy coding (Huffman, arithmetic, varints, gzip) gives common values short codes and rare values long ones.

Images: the same picture, four codecs

Live

A test image is drawn in your browser, then your browser's own encoders compress it. Move the quality slider and watch the lossy formats trade detail for bytes. PNG never changes, because it is lossless.

Original
This browser can't encode that format
at quality 60

Brain signals: why EEG needs its own codec

Live

A BrainBit headband sends 4 channels × 250 samples a second. Ten minutes is 600,000 numbers. Saved as JSON text, that is about 7 MB. gzip alone barely helps, because the noise in the last digits looks random to a byte-level compressor. Predict each sample from the last one or two first, and what is left is small and regular.

Generating signal…

AI models are compressors

Theory

Claude Shannon showed in 1948 that the smallest possible file for a message depends on how predictable it is: a symbol you expected with probability p costs −log₂ p bits. Give any predictor an arithmetic coder and it becomes a compressor. Better predictions give smaller files.

A language model is a next-token predictor, so it is also a compressor. In DeepMind's 2023 paper “Language Modeling Is Compression”, a large text-trained model compressed image patches and audio better than PNG and FLAC, although it had never been trained on either. The Hutter Prize rewards exactly this: compress Wikipedia better and you have built a better model of it.

That is why the BrainStream analysis agents work on features, not raw signal. Band powers, focus and relaxation are a lossy summary, a few numbers per second instead of a thousand, that keeps the part of the signal that means something. It is compression aimed at meaning rather than bytes.

Field guide

Reference
FormatKindHow it predicts and discards
PNGLossless imageEach row is predicted from the row above and the pixel to the left, then the leftovers are gzipped (DEFLATE).
JPEGLossy image, 1992Splits the image into 8×8 blocks, turns each into frequencies (DCT) and rounds away the fine high-frequency detail.
WebP / AVIFLossy image, modernBorrow video codecs: predict each block from nearby blocks, transform and quantise what is left. AVIF is usually about half the size of JPEG at the same look.
FLACLossless audioLinear prediction from past samples, then Rice-codes the residual. The same idea as our EEG codec below.
eegpack (.bbz)Lossless EEG, oursBrainStream's recording format: 0.001 µV quantisation, order-1 or order-2 prediction per channel, zigzag varints, gzip. Decodes bit-for-bit to the JSON export.
Neural codecsLearned image/audioA neural network learns the transform and the probability model together (Ballé et al., 2017). Google's SoundStream and Meta's EnCodec do this for audio.

How this site stays light

Practice

Mindstream ships no photos at all. Every visual is CSS, SVG or type, which is the best compression there is: no bytes.

Text, scripts and styles are served with Brotli or gzip. The one web font is self-hosted and subset to Latin. Any image added later is served through Next.js as AVIF, then WebP, sized to the screen.

BrainStream recordings can be saved as .bbz, about 5× smaller than JSON and bit-exact, and the replay loader reads them directly.