atbashcipher.com

Cipher Tutorials19 min read

Playfair Cipher Tutorial With Worked Examples

By Hommer Zhao, Founder & General ManagerView Hommer Zhao on LinkedIn
Table of contents (17 sections)

The Playfair cipher sits in a useful middle ground in the history of cryptography. It is clearly more sophisticated than a simple Caesar shift or an Atbash mirror, yet it is still compact enough to learn by hand in one sitting. That makes it one of the best classical ciphers for understanding a major transition in crypto design: the move from single-letter substitution to digraph substitution. Instead of encrypting one character at a time, Playfair encrypts pairs of letters. That one change removes the direct one-to-one mapping that makes simple monoalphabetic ciphers so easy to attack.

This tutorial explains the full Playfair process with worked examples. We will build the 5x5 key square, prepare plaintext correctly, apply the row, column, and rectangle rules, and then walk through decryption and common mistakes. If you want to test each step while reading, keep the Playfair cipher tool open alongside the Polybius square tool, the Four-Square cipher tool, and the Vigenere cipher tool. Those comparisons make it easier to see what Playfair improves and where its limits still remain. For definitions, our cryptography glossary and related articles on how to use Caesar cipher step by step and how to decode Vigenere cipher without the key are useful companions.

The short version is this: Playfair is a practical classroom cipher because it teaches key squares, digraph handling, plaintext normalization, and pattern leakage all at once. It is not secure by modern standards, but it is far more instructive than single-letter substitutions because the encryption logic forces you to think about how structure survives or changes under transformation.

Quick Answer: A Complete Playfair Example

With the keyword MONARCHY (I and J share one cell), the message HIDE THE GOLD becomes the digraphs HI DE TH EG OL DX and encrypts to:

BF CK PD FI MP BZ

Decrypting BF CK PD FI MP BZ with the same key returns HI DE TH EG OL DX, which reads HIDETHEGOLD plus the filler X added to complete the last pair.

Try it: open HIDE THE GOLD with the key MONARCHY in the Playfair tool (output BFCKPDFIMPBZ), or open the ciphertext in Decode mode (output HIDETHEGOLD, because the tool drops the trailing filler X). The three rules below produced every pair in that result:

Where the two letters sit Encrypt Decrypt MONARCHY example
Same row Take the letter to the right (wrap around) Take the letter to the left EG becomes FI
Same column Take the letter below (wrap around) Take the letter above BA becomes IB
Different row and column Keep your row, take the other letter's column Same swap (it is its own inverse) HI becomes BF

A second, independently published check: with the keyword PLAYFAIR EXAMPLE, the plaintext "Hide the gold in the tree stump" encrypts to BM OD ZB XD NA BE KU DM UI XM MO UV IF. This is the example used on Wikipedia's Playfair cipher article, and the Playfair cipher tool reproduces it exactly. Both results above were also recomputed with a separate, independent implementation, so you can use them to confirm your own square and your own by-hand work.

To check it, open "Hide the gold in the tree stump" with the key PLAYFAIR EXAMPLE and the tool returns BMODZBXDNABEKUDMUIXMMOUVIF. The double E in TREE is split as TR EX ES, which is why the plaintext grows by one letter.

What the Playfair Cipher Is and Why It Matters

The Playfair cipher is a classical digraph substitution cipher. In a monoalphabetic cipher such as Caesar, one plaintext letter always maps to one ciphertext letter. In Playfair, two plaintext letters are taken together as a pair, usually called a digraph or bigram, and the pair is encrypted using positions in a 5x5 key square. That makes repeated plaintext letters and common frequency patterns less transparent than they are in a single-letter system.

The method was first described by Charles Wheatstone in 1854, though it became widely known through Lord Playfair, whose name is attached to the cipher. Historically, it mattered because it offered a meaningful step up from simple substitution while remaining usable in the field with paper and pencil. It was not mathematically strong in the modern sense, but for manual cryptography in the nineteenth century it was efficient, memorable, and operationally plausible.

Playfair also matters educationally because it forces one important idea into view: security does not depend only on hiding letters. It depends on what linguistic structure still leaks after transformation. A single-letter substitution leaks individual letter frequencies almost untouched. A digraph cipher reshapes that leakage, but it does not eliminate it.

How the 5x5 Key Square Works

Everything in Playfair starts with the key square. Because the standard Latin alphabet has 26 letters and the square has only 25 cells, one letter must share a slot with another. The most common convention merges I and J, though some historical descriptions use other conventions. In practice, modern Playfair tutorials almost always treat I and J as the same square.

To build the square, write a keyword first, remove duplicate letters, then fill the remaining spaces with the rest of the alphabet in order, skipping the merged letter. If the keyword is MONARCHY, the square looks like this:

Column 1 Column 2 Column 3 Column 4 Column 5
M O N A R
C H Y B D
E F G I/J K
L P Q S T
U V W X Z

If you compare this with the Polybius square, the visual structure will feel familiar. The difference is in how the square is used. Polybius maps letters to coordinates. Playfair uses relative positions between two letters and transforms the pair according to spatial rules.

A good habit is to build the square slowly and verify three things before encrypting anything: the keyword has no repeated letters in the square, the alphabet fill order is correct, and I/J has been handled consistently. Most beginner errors happen before the first digraph is even processed.

Step 1: Prepare the Plaintext Correctly

Playfair plaintext preparation is not optional bookkeeping. It is part of the algorithm. First, remove spaces and punctuation if you are following the classical paper-and-pencil method. Second, convert everything to one consistent alphabet convention, usually uppercase with I/J merged. Third, split the message into digraphs. If a pair contains the same letter twice, insert a filler, commonly X, between them and continue pairing. If the message ends with a single unpaired letter, add a filler at the end.

Take the message HIDE THE GOLD. After removing spaces and merging conventions, you get HIDETHEGOLD. Then split into pairs:

HI DE TH EG OL DX

The final X is added because the total number of letters is odd. If the message were BALLOON, you would not write BA LL OO N as raw pairs. You would split it as BA LX LO ON, because the repeated L in the same digraph has to be separated by a filler.

This is the step many people skip when they try the Playfair tool for the first time. The tool helps automate the process, but understanding why the preparation matters is what lets you verify whether a result is correct. When a cipher has preprocessing rules, the same visible sentence can produce different ciphertexts if the rules are applied inconsistently.

Step 2: Learn the Three Encryption Rules

Once the plaintext is split into digraphs, every pair is encrypted using one of three geometric rules based on where the two letters appear in the square.

Rule 1: Same row. If both letters are in the same row, replace each one with the letter immediately to its right, wrapping around to the left side if necessary.

Rule 2: Same column. If both letters are in the same column, replace each one with the letter immediately below it, wrapping around to the top if necessary.

Rule 3: Rectangle rule. If the letters are in different rows and different columns, imagine the rectangle formed by their positions. Replace each plaintext letter with the letter in its own row but in the other letter's column.

That is the entire encryption system. The difficulty is not conceptual complexity. The difficulty is maintaining accuracy across a full message. If you want a contrast case, compare this with the Caesar cipher tool, where one shift rule applies everywhere, or the Four-Square cipher, which extends the digraph idea with multiple keyed squares.

Worked Example: Encrypting HIDE THE GOLD

Using the MONARCHY square above, let us encrypt the prepared digraphs HI DE TH EG OL DX one pair at a time.

HI: H is at row 2 column 2, and I/J is at row 3 column 4. They form a rectangle, so H becomes B and I becomes F. Result: BF.

DE: D is at row 2 column 5, and E is at row 3 column 1. Rectangle rule again. D becomes C and E becomes K. Result: CK.

TH: T is at row 4 column 5, and H is at row 2 column 2. Rectangle rule. T becomes P and H becomes D. Result: PD.

EG: E is at row 3 column 1, and G is at row 3 column 3. Same row. Move each one one step to the right. E becomes F, G becomes I/J. Result: FI if you write I for the merged square.

OL: O is at row 1 column 2, and L is at row 4 column 1. Rectangle rule. O becomes M and L becomes P. Result: MP.

DX: D is at row 2 column 5, and X is at row 5 column 4. Rectangle rule. D becomes B and X becomes Z. Result: BZ.

The final ciphertext is:

BF CK PD FI MP BZ

Many Playfair demonstrations use a similar example because it shows all the essential operations without being too long to track manually. Once you can do this by hand, you understand the cipher well enough to spot most implementation bugs or key-square mistakes.

Check this example in the Playfair tool: the key square and the six pairs above load with the link, and the output field should read BFCKPDFIMPBZ.

Worked Example: What Happens With Repeated Letters

Repeated letters are where Playfair starts to feel different from simple substitution. Consider the word BALLOON with the same key square.

First prepare the text correctly:

BA LX LO ON

The double L cannot remain inside one digraph, so an X is inserted after the first L. Now encrypt each pair:

  • BA is in the same column, so B becomes I/J and A becomes B.
  • LX forms a rectangle (L is in row 4, column 1; X is in row 5, column 4), so L becomes S and X becomes U.
  • LO forms a rectangle, so L becomes P and O becomes M.
  • ON is in the same row, so O becomes N and N becomes A.

The full ciphertext is IB SU PM NA (the tool prints I for the merged cell). The exact output depends on whether you render the merged square as I or J, but the teaching point is stable: repeated letters force text expansion and create visible preprocessing artifacts. Those artifacts are one reason Playfair can still leak useful structural information to an analyst.

Open BALLOON with the key MONARCHY in the Playfair tool: the output reads IBSUPMNA, and pressing Swap decodes it back to BALLOON with the filler X removed.

How Often Playfair Needs a Filler X: 1,000 Common Words Tested

To see how often the filler rules actually apply, we ran the 1,000 most frequent English words from the FrequencyWords list by Hermit Dave (OpenSubtitles 2018, CC BY-SA 4.0) through this site's Playfair encoder and decoder with the key MONARCHY on 2026-11-06. Each word was encrypted on its own, then decrypted, and the result was compared with the original word.

Result for 1,000 common words Words Share
Need at least one filler X54454.4%
Filler only because the word has an odd number of letters45145.1%
Filler because a doubled letter falls inside one pair (ALL, LOOK, KILL)939.3%
Decrypt back to exactly the original word99099.0%
Do not round-trip: every one contains J, which comes back as I (JUST to IUST)101.0%

Two practical points follow. More than half of the 1,000 words tested picked up at least one X, so in short messages like these an X in the decrypted text is more often a filler than a letter of the message. And the only losses in this test came from the I/J merge, not from filler removal, so if a decrypted word reads oddly, try putting a J back where an I appears. The counts depend on the word list and on single-word messages; longer sentences give different shares.

How Decryption Works

Decryption uses the same square but reverses the movement. If two ciphertext letters are in the same row, move each one one position to the left. If they are in the same column, move each one one position up. If they form a rectangle, the rectangle rule is symmetric, so you still take the other corner in the same row.

Take BF from the earlier example. B is at row 2 column 4, and F is at row 3 column 2. Rectangle rule gives H and I/J, restoring HI. For a same-row pair such as NA, you would move left to recover ON. For a same-column pair, you would move upward instead of downward. The only extra work comes after the full decryption: you may need to remove filler X characters when context makes it clear they were inserted artificially.

This is one reason the Playfair cipher tool is useful for practice. Decryption is mechanically simple, but it is easy to introduce one wrong row or column lookup and corrupt the rest of the message. A tool can confirm your manual output while you learn the pattern.

The same applies to J. The square has no separate J cell, so every I in a decrypted message may have been a J in the original. Read the result in context: IUST is JUST, and MAIOR is MAJOR.

Method Encryption Unit Key Material Main Strength Main Weakness
Playfair Cipher Digraphs One 5x5 keyword square Hides single-letter frequencies better than Caesar Still vulnerable to digraph pattern analysis
Caesar Cipher Single letters One shift from 1 to 25 Very easy to learn and apply Tiny keyspace and obvious frequency leakage
Atbash Cipher Single letters No secret key Simple reversible alphabet mirror Public rule with near-zero secrecy
Vigenere Cipher Single letters with repeating key Keyword Distributes frequency across multiple shifts Key length can often be inferred statistically
Four-Square Cipher Digraphs Four coordinated squares Stronger digraph substitution than Playfair More setup and more room for operator error
Modern Symmetric Encryption Binary blocks or streams Secret cryptographic key Real confidentiality at modern threat levels Requires proper implementation and key management

This comparison matters because many learners confuse “harder than Caesar” with “secure.” Playfair is more resistant than a basic shift cipher, but it is still a historical cipher. It belongs on a learning path that includes the Caesar cipher, the Playfair cipher, and later systems like the Vigenere cipher or Four-Square cipher, not in any serious modern confidentiality workflow.

Common Mistakes People Make With Playfair

The first common mistake is building the square incorrectly. Duplicate letters in the keyword, forgotten alphabet letters, and inconsistent I/J handling all produce wrong results that still look plausible enough to fool beginners. The second mistake is failing to preprocess repeated letters inside a digraph. The third is forgetting that filler X characters may need to be removed only after decryption and only when the language context supports that removal.

Another frequent issue is mixing conventions across examples. Some tutorials use X as the filler, others use Q, and some preserve J separately by dropping another letter from the 25-character square. None of those choices is automatically wrong, but once you choose one convention, it must remain stable from square construction through decryption. If you change conventions halfway through, you are no longer testing the same system.

A final mistake is assuming the cipher preserves readability in obvious chunks. It does not. Because Playfair works on pairs, word boundaries and familiar letter patterns distort quickly. That is why the frequency analysis tool can still be helpful in broader classical-cipher study, but simple single-letter counts are less decisive here than they are against a Caesar cipher.

How Playfair Is Broken in Practice

Playfair was historically stronger than basic monoalphabetic substitution, but it is still breakable. The reason is not a tiny keyspace like Caesar. The reason is that natural language still carries structure. Common digraphs such as TH, HE, ER, AN, and IN leave patterns, and the Playfair rules transform those patterns in systematic ways. Given enough ciphertext, an analyst can use digraph frequencies, probable words, repeated pair structures, and hill-climbing or simulated-annealing style search methods to recover likely key squares.

You do not need the full mathematics to understand the weakness. The important idea is that Playfair encrypts 2-letter units using fixed spatial rules from one square. That means the same plaintext digraph under the same key becomes the same ciphertext digraph every time. The system is stronger than single-letter substitution but still deterministic and still language-dependent.

If you have already read our article on how to decode Vigenere cipher without the key, the comparison is useful. Vigenere weakens single-letter frequency peaks by cycling through multiple shifts. Playfair changes the unit of substitution from one letter to two. Both are smarter than Caesar in different ways, but neither reaches modern cryptographic security.

When Playfair Is Worth Learning Today

Playfair is worth learning for at least four reasons. First, it gives you a concrete introduction to digraph substitution. Second, it teaches that preprocessing rules can be part of the cipher itself. Third, it gives historical context for why manual field ciphers evolved beyond simple shifts. Fourth, it shows that making a cipher more sophisticated does not automatically make it safe against determined analysis.

It is also excellent for hands-on practice. You can create a square in under 5 minutes, encrypt a sentence by hand, then check the result with the Playfair tool. After that, compare the same message in the Caesar cipher tool and the Vigenere cipher tool. That sequence shows how each system treats repetition, key material, and text structure differently.

What Playfair should not teach you is false confidence. It is a powerful historical teaching cipher, not a real security control. If your goal is confidentiality for modern data, use standard, peer-reviewed cryptographic libraries and definitions such as those reflected in the NIST cryptographic glossary, not hand-built classical methods.

A Practical Practice Workflow

  1. Choose a short keyword and build the 5x5 square slowly.
  2. Write a 20 to 40 letter plaintext with no punctuation.
  3. Prepare the digraphs, watching for duplicate letters and odd length.
  4. Encrypt each pair by hand and record the row, column, or rectangle rule you used.
  5. Check the result in the Playfair cipher tool.
  6. Decrypt your own ciphertext and remove filler letters only where the language clearly supports it.
  7. Compare the same plaintext in the Four-Square cipher tool or Vigenere cipher tool to see how different classical systems change pattern leakage.

That workflow is enough to make the algorithm feel concrete instead of abstract. It also exposes where your own mistakes usually happen, which is the fastest way to understand the cipher deeply.

FAQ

How do you set up a Playfair cipher key square?

Write the keyword first, remove duplicate letters, merge I and J into 1 square in the standard 25-cell layout, and then add the remaining unused letters of the alphabet in order until the 5x5 grid is complete.

Why does the Playfair cipher use letter pairs instead of single letters?

It encrypts digraphs because 2-letter units hide simple single-letter frequency patterns better than 1-letter substitutions. That gives Playfair more resistance than Caesar, even though it is still breakable with enough ciphertext.

What filler letter should you use in Playfair?

Most tutorials use X as the filler, and that is the safest convention for beginners. The important point is consistency: once you choose X or another filler, use the same rule in 100 percent of repeated-letter splits and every odd-length plaintext case.

Is Playfair cipher stronger than Caesar cipher?

Yes, in the limited classical sense. Playfair uses digraph substitution with a 25-cell key square, while Caesar uses only 1 shift value from a set of 25 possibilities. That makes Playfair harder to solve manually, but still not secure by modern standards.

Can you decrypt Playfair without the keyword?

Yes, sometimes. With longer ciphertexts, analysts can use digraph frequencies, repeated pair patterns, and search techniques to infer likely square layouts. The process is harder than breaking Caesar, but it is feasible on nontrivial texts.

Does Playfair decryption give back the exact original message?

Usually, but not always. In our test of 1,000 common English words with the key MONARCHY, 990 decrypted back to exactly the original word. The 10 that did not all contained J, which the 25-cell square stores as I, so JUST came back as IUST. Filler X letters can also be ambiguous when a message genuinely contains an X between two identical letters.

How can you recognize Playfair ciphertext?

Look for three signs. The ciphertext has an even number of letters, because it is written in pairs. It never contains J, because the square has no J cell. And a pair of two identical letters, such as ZZ, is very rare: it only appears when an X in the message lands next to a filler X, so the message XX encrypts to ZZZZ with the key MONARCHY. If all three hold and the text is not a simple substitution, Playfair is a good guess to try in the Playfair tool.

What is the difference between Playfair and Four-Square cipher?

Playfair uses 1 keyed 5x5 square and encrypts each digraph with 3 positional rules. Four-Square uses 4 coordinated squares, usually 2 of them keyed, which gives it stronger digraph substitution at the cost of more setup and operator effort.

Final Takeaway

The Playfair cipher is worth studying because it teaches more than a recipe. It teaches how changing the encryption unit from letters to digraphs alters what an attacker can immediately see. Once you understand the square, the preprocessing rules, and the three positional transformations, you can encrypt and decrypt by hand and also understand why the method eventually failed against determined analysis.

If you want to keep practicing, start with the Playfair cipher tool, compare it with the Polybius square, the Four-Square cipher, and the Vigenere cipher, then revisit our guides on Caesar cipher and Vigenere cryptanalysis. That progression gives you a much clearer map of how classical ciphers evolved.

Need help choosing the right classical cipher tool or understanding why a manual decryption result looks wrong? Visit our contact page and send the site team your question.

References

  1. Playfair cipher - Wikipedia
  2. FrequencyWords en_50k (OpenSubtitles 2018) by Hermit Dave, CC BY-SA 4.0 - word list used for the 1,000-word filler test
  3. Charles Wheatstone - Wikipedia
  4. Bigram - Wikipedia
  5. Frequency analysis - Wikipedia
  6. NIST Computer Security Resource Center Glossary
playfair ciphercipher tutorialdigraph substitutionclassical cryptographycryptanalysisplayfair examplesmanual encryption

Hommer Zhao

Founder & General Manager, Atbash Cipher Tools

Hommer Zhao runs Atbash Cipher Tools and reviews its free cryptography, encoding, and text-transformation tools and the guides on ciphers, encoding, and hashing.

View Hommer Zhao on LinkedIn →

Related Articles