This encoding fits the French flag into 11 bits

Compressing a Flag to 11 Bits

This encoding fits the French flag into 11 bits

Inspired by a video on matrix operations, I built a custom binary format that compresses any country flag into a handful of bits. Using Huffman trees for aspect ratios, color palettes, and layers, the average flag takes 76 bits—Indonesia's is just 11—and the longest, Qatar's, 420. A Base94 scheme keeps most flags under 12 characters, with a decoder and SVG renderer to bring them back.

Using this format, the average flag can be represented in 76 bits, with a median of 55 bits.
  1. kjgkjhfkjf

    In case anyone else was curious about using a lookup table: there are there are fewer than 256 recognized countries or territories [1], so 8 bits should be enough for a key.

    This would be superior to the 11-bit encoding presented here because it handles complexities such as coats of arms. It would also handle bizarre situations such as two countries having almost identical flags [2].

    [1] https://en.wikipedia.org/wiki/List_of_countries_and_territor...

    [2] https://www.worldatlas.com/articles/country-flags-that-resem...

  2. mabster

    Loved the title. I was like "that's 10 bits too many for a flag!" Haha

  3. fwlr

    There are exactly 64 flags excluded for having custom glyphs/seals/symbols/icons, which is crying out for an “appendix” lookup table to complete the encoding. The positions look very regular too, you could probably fit the positioning in the remaining 2 bits of a u8.

  4. blixt

    This reminds me of a great series on YouTube called "Can You Draw Every Flag in Powerpoint?"[1] and the guy does his darnedest to do it precisely, and in the process you learn just how specific (and sometimes non-specific) flags are!

    [1] Part 1: https://www.youtube.com/watch?v=w5QSVhgrqVE

  5. gerdesj

    A jack is a flag flown from a jackstaff, wot is found at the back of a ship or boat.

    The UK flag is called the Union Flag (it's a flag and it is a union of various flags and possibly nations too!) but let's face it, given how many people think its called the Union Jack, it doesn't really matter.

    If your flag pole at home is somewhat canted then I think you can call it a jackstaff, with a similar justification to the Royal Navy managing to designate their shore bases as ships. For example just up the road is HMS Heron (His Majesty's Ship: Heron).

    The Union Flag/Jack is only the flag of the UK by convention and not law. It's a bit wooley, just like our Constitution but it still all works.

    My point is that whilst I do enjoy this encoding scheme and it is jolly clever, reality is way more complicated. The UK's flag is pretty complicated but not alone. I'm pretty sure several flags have tassels, which I suppose strays into the coat of arms territory.

    How hard do you want to squint!

More from this day

2026-09-14