Skip to main content
Cryptography

The Playfair cipher: why pairing letters actually worked

Caesar, Atbash and ROT13 all fall to counting letters. Playfair's one change — encrypting two letters at a time instead of one — was enough to make that attack useless. Here's the grid, the rules, and where it still breaks.

Thien Nguyen
By Thien Nguyen
Updated September 5, 2026 · 7 min read
close-up of a vintage typewriter keyboard with round metal letter keys

The Caesar cipher, the Atbash cipher and ROT13 all share the same fatal habit: every occurrence of a given letter always encrypts to the same ciphertext letter. Count which ciphertext letter shows up most often, guess it's E, and the whole message unravels in minutes. That single flaw is why none of them were ever meant for real secrecy.

In 1854, Charles Wheatstone found the fix, and it wasn't a bigger key or a cleverer shift — it was refusing to encrypt one letter at a time at all. The Playfair cipher encrypts letters in pairs, and that one change is enough to break single-letter frequency analysis completely. It's named after Lord Playfair, who championed it to the British government rather than inventing it, and it went on to see real use as a field cipher in the Boer War and World War I.

Building the grid from a keyword

Everything starts with a 5×5 grid built from a keyword. Take PLAYFAIR EXAMPLE, strip anything that isn't a letter, drop repeated letters, and lay what's left across the grid — then fill the remaining cells with the rest of the alphabet in order:

P L A Y F
I R E X M
B C D G H
K N O Q S
T U V W Z

Notice there's no J. A 5×5 grid only has 25 cells, but the alphabet has 26 letters, so one has to give way. The standard convention merges I and J into a single cell — any J in the input is silently treated as I. Our Playfair cipher tool also offers an Omit Q variant, which drops the rarely-used Q instead and keeps I and J as separate letters — pick whichever variant, but the sender and receiver have to agree on it, same as the keyword itself.

Splitting the message into digraphs

Before any encryption happens, the plaintext gets chopped into letter pairs, called digraphs. Two rules keep the pairing from breaking:

  • A doubled letter can't pair with itself. BALLOON naturally splits as BA-LL-OO-N, but LL and OO would both encrypt a letter with itself, and the grid math doesn't have a rule for that case. So a filler letter (X by default; the tool lets you pick another) gets inserted between the repeat: BALLOON becomes BA LX LO ON.
  • A leftover single letter at the end gets padded. An odd-length message can't fully pair up, so the last letter is padded with the same filler.

Run Hide the gold in the tree stump. through the splitter and, once punctuation and spacing are stripped, you get thirteen clean pairs: HI DE TH EG OL DI NT HE TR EX ES TU MP.

The three encryption rules

Every digraph falls into exactly one of three cases, depending on where its two letters sit in the grid built above:

RuleDigraphPositions in the gridResult
Same row → shift each letter one cell right, wrapping at the edgeTUT and U both sit in the bottom rowUV
Same column → shift each letter one cell down, wrapping at the bottomDED and E both sit in the third columnOD
Rectangle (different row and column) → keep each letter's row, swap its column for the other letter'sTHT bottom-left, H middle-right — the two corners of a rectangleZB

This is the actual innovation, and it's easy to undersell it as "just do it twice." A row/column shift is Caesar's trick, reused — but the rectangle rule has no single-letter equivalent at all. It only exists because two letters are involved, and it's what makes the ciphertext for TH different from the ciphertext for HT: swap the two letters, and rows stay put but the column swap flips, so the output pair reverses too. A single-letter cipher can't produce an asymmetry like that — there's nothing to be asymmetric between.

Run the full sentence through those three rules and Hide the gold in the tree stump. comes out as BM OD ZB XD NA BE KU DM UI XM MO UV IF — a textbook example this tool reproduces exactly, letter for letter.

Decrypting reverses the row and column shifts (left instead of right, up instead of down); the rectangle rule undoes itself, since swapping columns twice gets you back where you started.

Why this actually beats letter-counting

Frequency analysis works on Caesar and Atbash because the ciphertext's letter distribution is just the English distribution, shuffled — count letters, find the spike, you've found E. Playfair never produces a single-letter ciphertext at all; there's no "the letter that appears most often" to map back to E, because every ciphertext letter came out of a pair, and which letter it becomes depends on its partner. The same T encrypts to different letters depending on whether it's paired with H, U, or anything else. Counting single letters in Playfair ciphertext tells an attacker almost nothing.

That's a genuinely different kind of attack surface than a bigger keyspace — a 5×5 grid from a memorable keyword produces "only" a few hundred thousand distinct grids, nowhere near the 25! theoretical maximum, since a keyword-driven alphabet skews toward common letter runs. The security here doesn't come from how many grids exist; it comes from single-letter counting no longer being the right tool for the job.

Where it still breaks

"No longer the right tool" isn't "no tool works." English has its own digraph frequencies — TH, HE, AN, IN, and ER dominate two-letter combinations the way E dominates single letters — and a long enough Playfair ciphertext still leaks that structure, just one level up. Digraph frequency analysis, first published in the 1940s, recovers the grid from a large enough sample the same way single-letter counting recovers a Caesar shift; modern automated solvers using hill-climbing search crack short Playfair messages in seconds.

There's a second, more direct weakness: the whole cipher is one 5×5 grid, with no additional key material mixed in per-message. A known-plaintext attack — an eavesdropper who correctly guesses even a short stretch of the original message — can start recovering grid positions directly from that single crib, then decrypt the rest of the message without ever running a statistical attack at all.

That combination is exactly why the British military adopted it as a field cipher rather than a strategic one. It's fast enough to encrypt and decrypt by hand with nothing but a memorized keyword and a pencil, and it holds up long enough to protect a message for the few hours a tactical order needs to stay secret — which was the actual job, not withstanding a patient cryptanalyst with unlimited time.

Where Playfair sits in the cipher family

Caesar / Atbash / ROT13VigenèrePlayfair
Unit encryptedOne letterOne letter (shift varies by position)A pair of letters
What breaks itSingle-letter frequency analysisKasiski examination / index of coincidence — the keyword repeatsDigraph frequency analysis, or a known-plaintext crib against the grid
Ciphertext letter frequencyMatches English, shuffledFlattens toward uniformFlattens for single letters; digraph structure still leaks
Real-world use todayPuzzles, spoiler text, teachingTeaching, historical re-creationPuzzles, CTFs, historical re-creation

Try it yourself

The Playfair cipher tool builds the grid and runs all three rules live in your browser — type a keyword and a message, and watch the row/column/rectangle cases play out on the pairs you actually typed rather than the textbook example above. Try feeding it a word with a doubled letter like BALLOON and watch the filler get inserted, or swap two letters in a digraph (THHT) and see the rectangle rule flip the output around them.

Once the pairing idea clicks, the rest of classical cryptography's arms race makes more sense: every cipher on this list beat the attack that came before it, right up until someone found the next pattern it forgot to hide.


Cover photo by Đậu Photograph on Pexels.

References

Primary documentation and specifications checked when this article was last updated.

CryptographyCiphersHistory

Related articles

All articles