Skip to content
Allin

The Caesar Cipher Explained: How Shift Ciphers and ROT13 Work

Published 7/21/2025 · 4 min read · Developer tools

Daniel Okonkwo

Daniel OkonkwoFront-end developer and tech writer at Allin

Web performance · File formats

Checked against 2 sources

View profile
In short

A Caesar cipher replaces each letter with the one a fixed number of positions later in the alphabet — a "shift." With a shift of 3, A becomes D, B becomes E, and so on, wrapping Z around to C. ROT13 is a Caesar cipher with a shift of 13, so applying it twice restores the original text. The cipher is trivial to break because there are only 25 possible shifts, so it offers no real security.

The Caesar cipher shifts every letter by a fixed amount. Learn how the shift works, why ROT13 is a special case, how to encode and decode by hand, and why the cipher offers no real security today.

How the shift works

Number the alphabet from 0 to 25, so A is 0, B is 1, up to Z which is 25. To encrypt with a shift of n, add n to each letter's number and take the result modulo 26, which wraps back to A after Z. For a shift of 3, the word "HELLO" becomes "KHOOR": H (7) → K (10), E (4) → H (7), L (11) → O (14), and O (14) → R (17).

Decrypting is the same process in reverse: subtract the shift instead of adding it, again modulo 26. Because the key is a single number between 1 and 25, the sender and receiver only have to agree on that one value. Letters that are not part of the alphabet — spaces, digits, punctuation — are normally left untouched, which is why the shape of the message often survives encryption.

ROT13, a self-reversing special case

ROT13 is simply a Caesar cipher with a shift of exactly 13 — half of the 26-letter alphabet. This gives it a neat property: because 13 + 13 = 26, which wraps all the way around, encoding and decoding are the same operation. Apply ROT13 to "HELLO" and you get "URYYB"; apply it again to "URYYB" and you are back to "HELLO." One function does both jobs.

Because of this, ROT13 was popular on early online forums not to hide secrets but to lightly obscure text — spoilers, punchlines, or offensive words — so a reader had to opt in to see it. It was never meant as encryption. It is a convention for "don't read this by accident," and everyone knew exactly how to reverse it.

Why it offers no real security

The Caesar cipher has only 25 usable keys, so an attacker can simply try every shift and read the one that produces sensible text — a brute-force attack that takes seconds by hand. Even without trying all shifts, frequency analysis breaks it fast: in English E is the most common letter, so the most common letter in the ciphertext usually reveals the shift immediately.

So treat the Caesar cipher as a teaching tool and a puzzle, not a way to protect anything that matters. It is a great first example for understanding modular arithmetic and keys, and it powers the letter-swap puzzles in games and escape rooms. For actual privacy, use modern algorithms like AES, which rely on keys far too large to guess by trying them all.

Caesar cipher (ROT13)Encode or decode text with a Caesar shift cipher — ROT13 by default.Try the tool

Frequently asked questions

What is the key in a Caesar cipher?
The key is a single number, the shift, from 1 to 25. It tells you how many positions to move each letter along the alphabet. Both sides must know this number to encrypt and decrypt.
Is ROT13 the same as the Caesar cipher?
ROT13 is a Caesar cipher with the shift fixed at 13. Because 13 is half of 26, encoding and decoding use the same operation — applying ROT13 twice returns the original text.
How do you decode a Caesar cipher without the key?
Try all 25 shifts and read whichever result makes sense — a brute-force attack. Alternatively, use frequency analysis: match the most common letter in the ciphertext to E, the most common letter in English, to guess the shift.
Can a Caesar cipher be used for real security?
No. With only 25 keys and vulnerability to frequency analysis, it is broken in seconds. Use it for learning and puzzles, and rely on modern ciphers like AES for anything that must stay private.

Articles you may find interesting

All guides

Related tools

Sources

Spotted a mistake in this article?