Skip to main content

Bacon Cipher Explained: Five Bits of A and B Hiding in Plain Text

How the Bacon cipher turns every letter into five A/B symbols, why it doubles as steganography hidden in typography, and how to crack it in CTFs and puzzles.

Published By Li Lei
#bacon cipher #cryptography #steganography #ctf #encoding

Bacon Cipher Explained: Five Bits of A and B Hiding in Plain Text

The first time I hit a Bacon cipher I did not even know it was a cipher. It was a CTF challenge with a paragraph of ordinary English, except half the letters were in italics. The message was not the words. The message was the styling. That is the whole trick Francis Bacon worked out in 1605, and it is why the Baconian cipher keeps showing up in puzzle hunts four centuries later.

This post walks through how it actually works, the one concrete rule you need, a fully worked example you can check by hand, and where it shows up in the wild. If you just want to encode or decode something right now, the Bacon cipher encoder and decoder does it in your browser with no upload.

Each letter is a five-symbol A/B code

Here is the single concrete fact the whole cipher rests on: every letter is replaced by a group of exactly five characters, and those characters are drawn from only two symbols, classically A and B.

Five positions, two choices each, gives 2 to the power 5, which is 32 patterns. The alphabet needs at most 26, so there is room to spare. You count up like binary. A is the smallest pattern, the next letter ticks the rightmost symbol over to B, and you carry as you go:

A = aaaaa     H = aabbb     O = abbba     V = babab
B = aaaab     I = abaaa     P = abbbb     W = babba
C = aaaba     J = abaab     Q = baaaa     X = babbb
D = aaabb     K = ababa     R = baaab     Y = bbaaa
E = aabaa     L = ababb     S = baaba     Z = bbaab
F = aabab     M = abbaa     T = baabb
G = aabba     N = abbab     U = babaa

Once you see that, the cipher stops being mysterious. It is binary with letters painted on top. Swap A and B for 0 and 1 and A becomes 00000, B becomes 00001, C becomes 00010, the exact counting any binary lesson uses. That is also why it is sometimes called a five-bit cipher.

A worked example you can check by hand

Let me encode the word CAB the slow way, so you can verify every group.

  • C is the third letter. Counting from A at zero: C sits at position 2, which is 00010 in binary, or in A/B form aaaba.
  • A is the first letter, position 0, 00000, so aaaaa.
  • B is the second letter, position 1, 00001, so aaaab.

Put them side by side and CAB becomes:

aaaba aaaaa aaaab

To decode, you do the reverse and it is mechanical: take the A/B stream, ignore every space, then slice it into chunks of five. aaaba | aaaaa | aaaab looks up as C, A, B. The grouping into fives is the only structure you need, which is also the cipher's weak point: anyone who counts to five can start decoding.

Try a longer one yourself. aabaa aabab aabaa aabbb aabaa is five groups, so five letters. Work each one against the table above and you get a real word. (It spells EFEHE only if you mis-slice it, so count carefully.)

Two alphabets: 24 letters versus 26

There is a historical wrinkle worth knowing before you decode someone else's message. Bacon's original 1605 table had only 24 codes, not 26. The Elizabethan alphabet did not cleanly separate I from J or U from V, so they shared patterns: I and J were one code, U and V another. In that scheme a J decodes back as I, and W comes out as a doubled V.

The modern 26-letter version gives every letter its own unique group, so J, U, V and W round-trip exactly. The practical consequence shows up the moment a decode goes wrong. If the start of a message reads fine and then collapses into garbage right after an I or a U, you are almost certainly using the wrong table. Toggle between 24 and 26 and the nonsense usually resolves into clean text. I have watched that one switch save a CTF round more than once.

Steganography: the message hides that it exists

Most ciphers scramble text into obvious gibberish. Bacon's design does the opposite, and that is its genius. The two symbols do not have to be the letters A and B at all. They can be any binary distinction you can hide inside a normal-looking document:

  • roman letters versus italic letters
  • capitals versus lowercase
  • one typeface versus a near-identical second typeface
  • bold versus regular weight

A reader skims an ordinary paragraph and sees nothing odd. Meanwhile every letter is silently flagged as A-type or B-type by its styling, and the real message rides along in groups of five. This is steganography in the strict sense: it hides the very fact that a message exists, not just its contents. That is exactly why escape rooms, alternate reality games and printed puzzle props lean on it. You encode a secret word to A/B, then map A to one font and B to another across a cover letter, and only the player who notices the two typefaces can transcribe the pattern back out.

It is also why the cipher belongs to its era. Bacon was a statesman as much as a philosopher, and a method for slipping a message past a censor who is staring right at it was genuinely useful in 1605.

It is not secure, and that is fine

Be clear about what the Bacon cipher is for. It is a fixed substitution: the same letter always produces the same five symbols, with no key. Once someone recognizes the A/B-in-fives structure, decoding is trivial; there is nothing to brute-force because there is no secret beyond the encoding scheme itself. The only real protection it ever offered was concealment, the steganographic layer, not cryptographic strength.

So use it for puzzles, teaching, CTF flags and ARG props, never for protecting anything that matters. If you want something with an actual key, a Vigenere cipher is the natural next step from here and a classic teaching follow-on. And if you are staring at a string that is clearly not Bacon, a substitution challenge often turns out to be something simpler in disguise.

A small but real privacy note: when you share a result link, the text and settings live in the URL, which means they land in chat logs and server access logs. For a genuine secret, copy the output text instead of sharing the link.

A quick mental checklist

When a wall of A and B characters lands in front of you, run these in order:

  1. Count the characters. The total should divide by five. If it does not, you are missing or have an extra symbol.
  2. Slice into fives and look each group up. Spaces and line breaks are just separators; ignore them.
  3. If the decode is almost-right but breaks after an I or U, switch the 24/26 alphabet.
  4. If it reads like a mirror of real text, your two symbols are reversed. The first symbol always fills the A position.

That four-step loop covers the vast majority of Baconian puzzles. The rest is patience and a lookup table, both of which the tool handles so you do not have to count groups of five by hand at 2 a.m. during a CTF.


Made by Toolora · Updated 2026-06-13