---
title: "Compressing a flag to 11 bits"
slug: compressing-a-flag-to-11-bits
url: https://listedarticles.com/articles/compressing-a-flag-to-11-bits
canonical_url: https://read.vantezzen.io/miniflags
content_type: blog_post
language: en
published_at: 2026-09-12T12:00:00.000Z
updated_at: 2026-09-16T16:12:45.470Z
author_url: https://read.vantezzen.io/
authored_by: agent
publisher: "vantezzen.io"
publisher_url: https://read.vantezzen.io
topics: ["Data Compression", "Algorithms", "Encoding", "Huffman Coding", "Vexillology"]
license: all-rights-reserved
word_count: 351
reading_minutes: 2
citation: "vantezzen.io. \"Compressing a flag to 11 bits.\" 12 Sept 2026. https://read.vantezzen.io/miniflags (all-rights-reserved)"
# The full text follows. The web page shows an extract and sends readers
# to the source above; quote the citation and link the canonical URL.
---

# Compressing a flag to 11 bits

> The author designs a compact binary encoding scheme for national flags using a layered model and Huffman coding. Most flags can be represented in 55–76 bits by exploiting the statistical regularity of flag elements — stripes, stars, crescents, common aspect ratios — while allowing longer codes for complex outliers like Qatar.

> **Indexed summary.** This entry is an agent-written synopsis of an article first published at [read.vantezzen.io](https://read.vantezzen.io/miniflags). Read the original for the full text.

The project starts from a simple observation: most national flags are combinations of a small number of recurring elements — horizontal or vertical stripes, stars, crescents, or crosses — with a limited palette dominated by red, white, blue, yellow, and green. If those statistical regularities can be exploited, a compact lossless-ish encoding is achievable.

The design defines flags as a sequence of layers (Stripe, Shape, Band, Region) whose parameters are each encoded using a separate Huffman tree trained on frequency data from all country flags. Common cases get very short codes; unusual values fall back to fixed-length free bits via a "Custom" escape value. Colors are grouped into generalised tones rather than exact hex codes, so Indonesia's flag — two equal horizontal stripes, red over white, 2:3 aspect ratio — encodes to just 11 bits.

## Key points

- Aspect ratios follow a Zipf-like distribution: 2:3 appears in 45% of flags, 1:2 in 28%, 3:5 in 9%, with a long tail handled by a custom width/height encoding.
- Colors are mapped to approximate tonal groups (Red, White, Blue, etc.) rather than exact values; custom 10-bit RGB approximations are available for unusual shades.
- The layered model handles stripes, shapes (stars, crescents, circles), left-side triangles, top-left rectangles, Nordic crosses, and the Union Jack as named layer types.
- The median flag encodes in 55 bits; the average is 76 bits. Qatar is the longest at 420 bits, requiring 11 rectangle layers to approximate its serrated edge.
- The author used Codex to generate an encoder/decoder and SVG renderer, then shrunk the combined result from two separate files to a single 470-line, 5.29 kB TypeScript module.

## Why it matters

The piece is an accessible, end-to-end walkthrough of applying information theory to a concrete, visual domain. It shows how Huffman coding, schema design, and statistical analysis of a real-world corpus interact — and demonstrates that "can I compress this?" is often a rewarding question to ask about structured visual data.

---

*Source: [Compressing a flag to 11 bits](https://read.vantezzen.io/miniflags)*
