ROT13 (“rotate by 13 places”) is a simple letter-substitution cipher that shifts each letter halfway around the alphabet. It became famous on Usenet newsgroups as a polite way to hide spoilers, punch lines and puzzle answers — readers had to deliberately decode the text to see it. It is still widely used in puzzle hunts and as a teaching example.
The rotation rule
For each letter, ROT13 adds 13 to its position in the alphabet and wraps around if it passes Z. In formula terms, an uppercase letter at position p (where A is 0) maps to position (p + 13) mod 26. So A (0) becomes N (13), and N (13) becomes A again because (13 + 13) mod 26 = 0. Lowercase letters follow the same rule independently, and case is preserved. Any character that is not an ASCII letter — a digit, space or symbol — is copied through unchanged.
The defining property is that ROT13 is its own inverse. Applying it twice rotates a total of 26 places, a full loop, returning the original letter. That is why a single tool both scrambles and unscrambles, with no separate “decode” mode needed.
The full alphabet mapping
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
Read the top row as input and the bottom row as output (and vice versa). Every letter pairs with the letter 13 positions away. The same table works in both directions.
Worked example
Encoding the message “Hide spoiler: Han Solo dies”:
- H → U
- i → v
- d → q
- e → r
- (space preserved)
- s → f
- p → c
- o → b
- i → v
- l → y
- e → r
- r → e
The phrase “Han Solo” rotates to “Una Fbybf” — perfectly opaque at a glance. Running the output back through ROT13 restores the original immediately.
Why ROT13 specifically?
The reason ROT13 became the de facto spoiler cipher is precisely because 13 is half of 26. Any other rotation (ROT7, ROT20) requires a separate key and a different decode step. With ROT13, the same Usenet newsreader command that encoded the message also decoded it — no key, no mode switch, no mental arithmetic.
A two-thousand-year family tree
ROT13 is the modern special case of the Caesar cipher. The Roman historian Suetonius records that Julius Caesar protected private correspondence by shifting each letter three places — a ROT3, in today’s terms. Every rotation cipher shares the Caesar cipher’s fundamental weakness: there are only 25 possible shifts, so an attacker can simply try them all, and frequency analysis (the fact that E, T and A dominate English text) breaks it even faster on longer messages. That weakness is exactly why ROT13 survived — once a cipher offers no security anyway, you might as well pick the shift that makes encoding and decoding the same operation.
The name and culture around ROT13 grew up on 1980s Usenet, where newsreader software shipped a built-in ROT13 command for spoilers and off-colour jokes; the Jargon File’s rot13 entry documents the convention (and Britannica’s Caesar cipher entry covers the two-millennia backstory). The pattern still appears in odd corners of real software — Windows famously stores some registry values (the UserAssist keys that track program launches) obfuscated with ROT13, a reminder that it hides data from casual reading and nothing more.
One-liners in common languages
# Unix tr
tr 'A-Za-z' 'N-ZA-Mn-za-m' <<< "Hello"
// JavaScript
s.replace(/[a-z]/gi, c => String.fromCharCode(
c.charCodeAt(0) + (c.toLowerCase() < "n" ? 13 : -13)));
# Python — built into the standard codecs
import codecs; codecs.encode("Hello", "rot13")
Python shipping ROT13 as a standard codec says everything about its status: it is a text transform, not a security measure.
What ROT13 does to non-English text
The rotation is defined over the 26-letter ASCII alphabet only, so accented letters (é, ü, ñ), Cyrillic, Greek, CJK characters and emoji pass through completely unchanged. That means ROT13 does not hide text written in most languages other than English — a French sentence keeps every accented letter readable, and a Russian sentence is untouched entirely. If you need to obscure mixed-script text from casual view, ROT47 (which rotates all printable ASCII) still won’t touch non-ASCII characters; base64 encoding is the usual pragmatic choice for making arbitrary text unreadable at a glance.
Related tools
| Variant | Rotates | Self-inverse? |
|---|---|---|
| ROT5 | Digits 0–9 only | Yes (5 is half of 10) |
| ROT13 | Letters A–Z only | Yes (13 is half of 26) |
| ROT18 | Letters + digits (ROT13 + ROT5) | Yes |
| ROT47 | All printable ASCII 33–126 | Yes (47 is half of 94) |
| ROT-N | Letters, any shift you pick | Only when N = 13 |
ROT13 only touches the 26 Latin letters. Use ROT47 to also rotate digits and punctuation, or ROT-N to choose a different shift. Treat it as obfuscation, not encryption — it has no key and the mapping is public.