π Caesar Cipher Encoder and Decoder
By Shihab Mia Β· Updated 2026-06-27
Enter some text to see the cipher result.
A Caesar cipher shifts every letter in your message a fixed number of places along the alphabet, so A with a shift of 3 becomes D and Z wraps back round to C. Type or paste your text, choose a shift from 1 to 25, and pick encode or decode. The result updates instantly, case is preserved, and spaces, numbers and punctuation are left exactly as they are.
What is the Caesar Cipher?
The Caesar cipher is one of the oldest and simplest encryption methods, named after Julius Caesar, who reportedly used a shift of 3 to protect his military messages around 58 BCE. It is a monoalphabetic substitution cipher: each letter of the plaintext is replaced by the letter a fixed number of positions further down the alphabet. With a shift of 3, A maps to D, B maps to E, and so on, with X, Y and Z wrapping around to A, B and C. Only the 26 letters are touched, so digits, spaces and punctuation pass through unchanged, and the case of each letter is preserved.
Decoding is just encoding in reverse. If a message was encoded with a shift of 3, you decode it by shifting every letter back by 3, which is the same as shifting forward by 26 minus 3, that is 23. Because the alphabet is a closed loop of 26 letters, shifting forward by 23 lands you in exactly the same place as shifting back by 3. That is why a Caesar cipher decoder can recover text simply by applying the complementary shift, and why a shift of 13 (ROT13) is its own inverse: shifting twice by 13 returns you to the start.
Mathematically the cipher is pure modular arithmetic. Number the letters A=0 through Z=25, and encryption is the formula C = (P + k) mod 26, where P is the plaintext letter number and k is the shift, or key. Decryption is P = (C - k + 26) mod 26. The mod 26 is what produces the wrap-around at the end of the alphabet, and it is the same idea as a clock face wrapping from 12 back to 1. This makes the Caesar cipher a popular first example when teaching cryptography, because the whole scheme fits in a single line of maths.
The Caesar cipher is fun and useful for puzzles, learning and lightly obscuring text such as spoilers, but it offers no real security. There are only 25 usable shifts, so an attacker can simply try them all in seconds, a method called brute force. It can also be broken by frequency analysis, since the most common letter in the ciphertext usually corresponds to a common letter like E in English, which makes up about 12.7 percent of typical text. More rigorous solvers use a chi-squared test that compares the whole letter distribution of each candidate shift against expected English frequencies and picks the closest match automatically.
The Caesar cipher sits inside a wider family of classical ciphers. ROT13 is the special case with a shift of 13, often used to hide spoilers and answers on forums. The Vigenere cipher generalises Caesar by using a keyword so the shift changes from letter to letter, which defeats simple frequency analysis. The Atbash cipher reverses the alphabet instead of shifting it, and the affine cipher multiplies as well as adds. Understanding the plain Caesar shift is the gateway to all of these, which is why it remains the standard starting point in cryptography courses and capture-the-flag puzzles. For anything that genuinely needs protecting, use modern encryption such as AES rather than any shift cipher.
When to use it
- Solving or creating Caesar cipher puzzles in escape rooms, treasure hunts, geocaching and classroom exercises.
- Teaching the basics of cryptography, substitution and modular arithmetic in an interactive, hands-on way.
- Lightly hiding spoilers, puzzle answers or surprises so they are not readable at a glance, the classic ROT13 use.
- Decoding an intercepted message when you know, or want to guess, the shift that was used.
- Quickly testing all 25 shifts to brute force an unknown Caesar cipher and find the readable plaintext.
- Building or checking cryptography homework, capture-the-flag (CTF) challenges and coding exercises.
How to use the Caesar Cipher
- Type or paste the text you want to transform into the input box.
- Choose a shift from 1 to 25 (3 is the classic Caesar shift, 13 is ROT13).
- Pick Encode to shift letters forward, or Decode to shift them back.
- Read the result below and use the Copy button to grab it.
- If you do not know the shift, decode with each value from 1 to 25 until the output reads as plain language.
Formula & method
Worked examples
Encode the word HELLO with a shift of 3 (the classic Caesar cipher).
- H is position 7, so 7 + 3 = 10, which is K
- E is position 4, so 4 + 3 = 7, which is H
- L is position 11, so 11 + 3 = 14, which is O
- L again gives O
- O is position 14, so 14 + 3 = 17, which is R
Result: HELLO becomes KHOOR
Decode KHOOR, knowing it was encoded with a shift of 3.
- Decoding shifts back by 3, the same as shifting forward by 26 - 3 = 23
- K is position 10, so 10 + 23 = 33, and 33 mod 26 = 7, which is H
- H gives 7 + 23 = 30, 30 mod 26 = 4, which is E
- O gives 14 + 23 = 37, 37 mod 26 = 11, which is L (twice)
- R gives 17 + 23 = 40, 40 mod 26 = 14, which is O
Result: KHOOR decodes back to HELLO
Apply ROT13 to the word HELLO and show it is its own inverse.
- ROT13 is a Caesar cipher with shift 13
- H (7) + 13 = 20, which is U
- E (4) + 13 = 17, which is R
- L (11) + 13 = 24, which is Y (twice)
- O (14) + 13 = 27, 27 mod 26 = 1, which is B
- Applying ROT13 again to URYYB returns HELLO, because 13 + 13 = 26 is a full loop
Result: HELLO becomes URYYB, and ROT13 of URYYB is HELLO again
Full A to Z mapping for the classic Caesar shift of 3 and ROT13 (shift 13)
| Plain | Shift 3 | ROT13 | Plain | Shift 3 | ROT13 |
|---|---|---|---|---|---|
| A | D | N | N | Q | A |
| B | E | O | O | R | B |
| C | F | P | P | S | C |
| D | G | Q | Q | T | D |
| E | H | R | R | U | E |
| F | I | S | S | V | F |
| G | J | T | T | W | G |
| H | K | U | U | X | H |
| I | L | V | V | Y | I |
| J | M | W | W | Z | J |
| K | N | X | X | A | K |
| L | O | Y | Y | B | L |
| M | P | Z | Z | C | M |
Notable shift values and what they do
| Shift | Name | Note |
|---|---|---|
| 3 | Caesar shift | The shift Julius Caesar is said to have used. |
| 13 | ROT13 | Its own inverse: encode and decode use the same shift. |
| 1 to 25 | General Caesar | Any of these 25 shifts gives a valid cipher. |
| 0 or 26 | No shift | Leaves the text unchanged, so it is not used. |
Most common English letters used in frequency analysis
| Letter | Approx. frequency | Use when cracking |
|---|---|---|
| E | 12.7% | The most common ciphertext letter often maps to E. |
| T | 9.1% | Second most common, helps confirm the shift. |
| A | 8.2% | Common; useful as a cross-check. |
| O | 7.5% | Common vowel for verifying a guess. |
| I | 7.0% | Frequent letter in short words like I and IN. |
| N | 6.7% | Pairs well with vowels to spot real words. |
Common mistakes to avoid
- Decoding with the wrong shift. To read a message you must use the same shift it was encoded with. If you do not know it, try each of the 25 shifts until the output reads as plain language, this is the brute-force approach.
- Expecting it to be secure. A Caesar cipher has only 25 possible keys and is trivial to break by trying them all or by frequency analysis. Treat it as a puzzle or obfuscation, never as real encryption for sensitive data.
- Thinking ROT13 needs a separate decode step. ROT13 is a shift of 13, and 13 + 13 = 26, a full loop. Applying ROT13 a second time returns the original text, so encode and decode are the same operation.
- Forgetting that only letters shift. Numbers, spaces and punctuation are not part of the 26-letter alphabet, so they stay exactly as they are. If you expected a digit or symbol to change, that is why it did not.
- Confusing encode and decode direction. Encoding shifts letters forward and decoding shifts them back by the same amount. Picking the wrong direction gives gibberish, so check that you are on the right mode before reading the result.
- Assuming the same shift works for every cipher. A Caesar cipher uses one fixed shift, but a Vigenere cipher changes the shift with a keyword. If a single shift never produces readable text across all 25 values, the message likely uses a different cipher.
Glossary
- Plaintext
- The original, readable message before it is encrypted.
- Ciphertext
- The scrambled output produced after the cipher is applied.
- Shift (key)
- The fixed number of positions each letter moves along the alphabet, from 1 to 25.
- Substitution cipher
- A cipher that replaces each letter with another according to a fixed rule, as the Caesar cipher does.
- ROT13
- A Caesar cipher with a shift of 13 that is its own inverse, so the same operation encodes and decodes.
- Brute force
- Trying every possible key in turn, which breaks a Caesar cipher in at most 25 attempts.
- Frequency analysis
- Cracking a cipher by matching common ciphertext letters to common language letters like E and T.
- Modular arithmetic
- Maths that wraps around a fixed range, here mod 26, so Z plus one returns to A.
Frequently asked questions
What is a Caesar cipher?
A Caesar cipher is a substitution cipher that shifts every letter in a message a fixed number of places along the alphabet. With a shift of 3, A becomes D, B becomes E, and Z wraps around to C. It is named after Julius Caesar, who is said to have used a shift of 3 for his correspondence.
How do I decode a Caesar cipher?
Decode by shifting each letter back by the same number it was encoded with. In this tool, set the same shift and choose Decode. If you do not know the shift, try each of the 25 possibilities until the text reads as plain language, which is the brute-force method.
How do I solve a Caesar cipher without knowing the shift?
Use brute force or frequency analysis. Brute force means decoding with every shift from 1 to 25 and reading which output makes sense. Frequency analysis is faster: find the most common letter in the ciphertext, assume it maps to E, and the gap between them gives the likely shift.
Is ROT13 a Caesar cipher?
Yes. ROT13 is simply a Caesar cipher with a shift of 13. Because 13 is exactly half of 26, applying it twice returns the original text, so the same operation both encodes and decodes. Set the shift to 13 here to use it.
Is the Caesar cipher secure?
No. With only 25 usable shifts it can be broken almost instantly by trying every key, and the letter patterns can be cracked with frequency analysis. It is great for puzzles and learning, but never use it to protect sensitive information. Use modern encryption like AES for real security.
What is the formula for the Caesar cipher?
Number the letters A=0 to Z=25. To encrypt, use C = (P + shift) mod 26, and to decrypt, use P = (C - shift + 26) mod 26. The mod 26 produces the wrap-around at Z, just like a clock face wraps past 12.
What happens to numbers and punctuation?
Only the 26 letters A to Z, in both cases, are shifted. Digits, spaces, punctuation and symbols pass through unchanged, and the case of each letter is preserved, so an uppercase letter stays uppercase.
What shift should I use?
Any shift from 1 to 25 works. A shift of 3 is the classic Caesar choice, and 13 gives you ROT13. A shift of 0 or 26 would leave the text unchanged, which is why those are not offered.
What is the difference between a Caesar cipher and a Vigenere cipher?
A Caesar cipher uses one fixed shift for the whole message, while a Vigenere cipher uses a keyword so the shift changes from letter to letter. That repeating key makes the Vigenere cipher much harder to crack with simple frequency analysis.
Who invented the Caesar cipher and when?
It is named after Julius Caesar, the Roman general and statesman, who reportedly used a shift of 3 to protect military messages around 58 BCE. It is one of the earliest documented encryption methods in Western history.