Size Coding
The art of compression
Size coding emerged from demo scene competitions with strict byte limits, pushing programmers to achieve impossible effects in 64KB, 4KB, or even 256 bytes.
Overview
How much can you fit in 64 kilobytes? What about 4 kilobytes? 256 bytes? The demo scene answered these questions with productions that seemed to defy physics. Size coding — creating complex audiovisual productions under strict byte limits — became an art form. The techniques developed fed into game compression, procedural generation, and efficient programming practices.
Fast facts
- Origin: Demo scene size competitions (late 1980s).
- Categories: 64K, 4K, 1K, 256 bytes, smaller.
- Techniques: Procedural generation, compression, mathematical synthesis.
- Influence: Game engines, web development, embedded systems, JavaScript code-golf.
Size categories
| Category | Limit | Challenge |
|---|---|---|
| Demo | Unlimited | Full artistic expression |
| 64K intro | 65,536 bytes | Procedural textures, music, scenes |
| 4K intro | 4,096 bytes | Extreme compression, single-pass synth |
| 1K intro | 1,024 bytes | Minimalist effects, raymarchers |
| 256 byte | 256 bytes | Pure code golf, single effect |
| 32 / 64 byte | 32 / 64 bytes | Single instruction-level idea |
Legendary productions
| Production | Size | Achievement |
|---|---|---|
| .kkrieger | 96 KB | Complete first-person shooter (Farbrausch, 2004) |
| Elevated | 4 KB | Mountain landscape flythrough (Rgba/TBC, Breakpoint 2009) |
| fr-08: .the .product | 64 KB | Full 3D engine with procedural textures and music (Farbrausch, 2000) |
| chaos theory | 256 bytes | Iconic C64 256-byte effect (Conspiracy/Atebit) |
| Memories | 4 KB | Atari 8-bit raymarched scene |
| A Mind Is Born | 256 bytes | Full C64 production with music and visuals (Linus Åkesson, 2017) |
Techniques
Procedural generation
Replace stored content with code that generates it. A single trig formula computes a 256×256 cloud texture; a noise function fills a height-field; an L-system grows a tree. The 4 KB demos Elevated and Cdak generate entire mountain landscapes from one ray-march loop and a couple of sine-based noise functions.
Mathematical textures
// 4-byte expression generating a checker pattern
((x ^ y) & 8) ? 1 : 0
Plasma, marble, wood, fire, water — all common demo textures fall out of two or three sines plus an absolute value. The "shader" is shorter than the texture file would be.
Executable compression
The compiled binary is fed to a compressor that emits an unpack stub plus compressed data. Standard tools:
| Compressor | Platform | Typical use |
|---|---|---|
| Crinkler | Windows x86 | 4 KB / 64 KB intros — context-mixing arithmetic coder |
| Aplib | Cross-platform | LZSS variant, fast decompression |
| Exomizer | C64 / 6502 | The C64 community standard |
| kkrunchy | Windows x86 | Used by Farbrausch (.kkrieger and friends) |
| upx | Cross-platform | Generic; used for normal binaries, not size-tight intros |
A 4 KB intro typically runs the binary through multiple passes: dead-code elimination, custom linker scripts, then crinkler. Five hundred bytes of output for ten kilobytes of source is normal.
Synthesised audio
Stored samples are too big. Instead: single-pass softsynth. A short oscillator routine generates each note, instrument envelopes are computed live, the song is a list of (note, length, instrument) tuples. Tools like 4klang (Windows 4 KB) and Clinkster (small-intro audio) ship with whole synths in under 1 KB. On retro platforms the SID and AY chips already are softsynths in hardware — the song data dominates rather than the audio code.
Imports / API minimisation
On Windows, calling kernel32.dll requires loading the function pointer table. A 4 KB intro skips the standard linker and walks the PE export tables itself, costing ~30 bytes of stub vs ~200 bytes of normal import handling. On retro platforms the analogue is direct hardware access instead of going through KERNAL/BIOS routines.
Code golf
Single-effect 256-byte productions are mostly hand-crafted assembly where every byte is justified. Common tricks:
- Reuse a single arithmetic register for both pixel coordinate and frame counter
- Self-modifying code so two pieces of logic share one instruction
- Use
RST 0/JMP $0000style for hardware initialisation by re-entering the boot loader - Pack constants into instruction operands that double as data
Modern applications
Size-coding discipline appears in:
- Web performance — minified bundles, tree-shaking, server push budgets
- Embedded systems — fitting firmware in a few KB of flash
- Game asset compression — Steam / store-page download budgets
- Demakes and fan projects — fitting a modern game's idea on retro hardware
- JavaScript 1k / 13k contests — js13kgames, Code Golf, 1k JS contest