How the Caesar Cipher Works and How to Crack One Without the Key

Learn how the Caesar shift cipher encrypts letters, the modular arithmetic behind it, and how brute force and letter frequency analysis crack it in seconds.

Updated September 29, 2026 6 min read

Use the free Caesar CipherEncrypt or decrypt with any shift, or brute-force all 25 shifts

The Caesar cipher is the first cipher most people ever meet. It appears in school maths lessons, escape rooms, puzzle hunts, capture-the-flag security challenges and children's spy kits. According to the Roman historian Suetonius, Julius Caesar used it with a shift of three to protect his private letters, which is how it got its name.

This guide explains how the cipher works, the simple formula behind it, why it is trivially easy to break, and how to crack a message when you do not know the shift, using both brute force and letter frequency analysis.

How the cipher works

A Caesar cipher replaces each letter with the letter a fixed number of positions further along the alphabet. That fixed number is the shift, and it is the only "key". With a shift of 3:

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

"Meet me at noon" becomes "Phhw ph dw qrrq". Letters near the end of the alphabet wrap around to the start, so X becomes A, Y becomes B and Z becomes C.

To decrypt, you shift each letter back by the same amount.

The formula

Number the letters A = 0 to Z = 25. For a shift of k:

Encrypt:  C = (P + k) mod 26
Decrypt:  P = (C − k) mod 26

The mod 26 part is what makes the alphabet wrap around, like a clock. This makes the Caesar cipher a neat introduction to modular arithmetic.

Special shifts

  • A shift of 0 or 26 changes nothing.
  • A shift of 13 is ROT13, which is its own inverse; see our explainer on what ROT13 is.
  • Decrypting with shift k is the same as encrypting with shift 26 − k. Decrypting a shift of 3 is encrypting with 23.

Why the Caesar cipher is weak

There are only 25 useful shifts. Anyone who suspects a Caesar cipher can simply try all of them, and one will produce readable text. This is called a brute-force attack, and for the Caesar cipher it takes seconds by hand and microseconds by computer.

Even without trying every shift, the cipher leaks the structure of the language. Every E becomes the same letter, so the most common ciphertext letter is likely to be E, and word lengths and punctuation remain unchanged. That leads to the second attack.

Frequency analysis

In typical English text, some letters are far more common than others. E, T, A, O, I and N appear frequently; J, Q, X and Z are rare. A Caesar shift moves the whole pattern along the alphabet without changing its shape. By comparing the ciphertext's letter counts with the usual English pattern for each possible shift, you can pick the shift whose result looks most like English.

A standard way to score "looks like English" is the chi-squared statistic: for each letter, compare the observed count with the expected count, square the difference and divide by the expected count, then add them up. The lowest score wins. This works very well on a sentence or more of text, but for a few words the counts are too small to be reliable.

Encrypt, decrypt or crack a Caesar cipher in your browser

Our Caesar Cipher tool does all three.

Encrypt or decrypt with a known shift

  1. Open Caesar Cipher and choose Encrypt or Decrypt.
  2. Type or paste your text. Sample loads a short message in the matching mode.
  3. Set the Shift with the slider, from 1 to 25. The label shows what A becomes, and notes when the shift equals ROT13.
  4. Turn on Also shift digits if numbers should rotate too (0-9, wrapping after 9). Leave it off for the classic letters-only cipher.
  5. Copy or download the result from Encrypted text or Decrypted text.

Capital letters stay capital, and spaces and punctuation are unchanged.

Crack an unknown shift

  1. Choose Brute force (unknown shift).
  2. Paste the ciphertext.
  3. The output, All 25 possible shifts, lists every candidate. The one closest to normal English letter frequencies is marked "★ most English-like".
  4. Scan the list to confirm. For very short messages, the star can pick the wrong shift, but the correct plain text will still be in the list and easy to spot by eye.

Other ways to work with Caesar ciphers

By hand with a cipher wheel

Two concentric paper discs with the alphabet around the edge make a cipher wheel. Turn the inner disc by the shift and read across. Classrooms use these because they make the wrap-around visible.

In a spreadsheet

Spreadsheets can apply a shift with CHAR, CODE and MOD formulas on each character, split out using MID. It works, but it is a lot of formula for a small task, so it is mainly useful as a teaching exercise.

On the command line

tr can apply any fixed shift. A shift of 3 is:

echo "Meet me at noon" | tr 'A-Za-z' 'D-ZA-Cd-za-c'

Swap the two sets to decrypt. Scripts in Python or JavaScript can brute-force all 25 shifts in a few lines.

Tips for puzzles and challenges

Check whether it is really a Caesar cipher

If none of the 25 shifts produces readable text, the message probably uses something else: a keyword cipher, a Vigenère cipher, a substitution alphabet, or an encoding such as Morse code, binary or Base64. Encodings are recognisable by their character sets: only dots and dashes, only 0s and 1s, or letters, digits, + and / often ending in =.

Watch for reversed text

Puzzle setters sometimes shift and reverse a message. If no shift works, try Reverse Text first and brute force again.

Keep the spacing

Word lengths are a strong clue. A three-letter word that appears often is likely "the" or "and", which can tell you the shift before you try anything else.

Never use it for real secrets

The Caesar cipher is a teaching and puzzle tool. It provides no protection for passwords or personal data.

Frequently asked questions

How does a Caesar cipher work?

Each letter is replaced by the letter a fixed number of places later in the alphabet, wrapping from Z back to A. Decryption shifts letters back by the same amount.

How do I decode a Caesar cipher without the key?

Try all 25 possible shifts and look for readable text, or use frequency analysis to rank the shifts. The brute-force mode in our tool does both.

What shift did Julius Caesar use?

Suetonius describes Caesar using a shift of three, so A was written as D. That is why a shift of 3 is the classic example.

Is ROT13 a Caesar cipher?

Yes. ROT13 is a Caesar cipher with a shift of 13. Because 13 is half the alphabet, encrypting twice returns the original text.

Does the Caesar cipher work on numbers?

The classic cipher only shifts letters. Our tool can optionally shift digits too, rotating them within 0-9.

Try it now: Caesar Cipher

Loading tool…