Skip to content
Techniques & Technology

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.

commodore-64commodore-amigaibm-pcsinclair-zx-spectrum demooptimisationprogramming 1987–present

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

CategoryLimitChallenge
DemoUnlimitedFull artistic expression
64K intro65,536 bytesProcedural textures, music, scenes
4K intro4,096 bytesExtreme compression, single-pass synth
1K intro1,024 bytesMinimalist effects, raymarchers
256 byte256 bytesPure code golf, single effect
32 / 64 byte32 / 64 bytesSingle instruction-level idea

Legendary productions

ProductionSizeAchievement
.kkrieger96 KBComplete first-person shooter (Farbrausch, 2004)
Elevated4 KBMountain landscape flythrough (Rgba/TBC, Breakpoint 2009)
fr-08: .the .product64 KBFull 3D engine with procedural textures and music (Farbrausch, 2000)
chaos theory256 bytesIconic C64 256-byte effect (Conspiracy/Atebit)
Memories4 KBAtari 8-bit raymarched scene
A Mind Is Born256 bytesFull 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:

CompressorPlatformTypical use
CrinklerWindows x864 KB / 64 KB intros — context-mixing arithmetic coder
AplibCross-platformLZSS variant, fast decompression
ExomizerC64 / 6502The C64 community standard
kkrunchyWindows x86Used by Farbrausch (.kkrieger and friends)
upxCross-platformGeneric; 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 $0000 style 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 contestsjs13kgames, Code Golf, 1k JS contest

See also