A Rail Fence cipher decoder example starts with the classic 25-letter phrase WEAREDISCOVEREDFLEEATONCE, which the historical three-rail zigzag transposition rearranges to WECRLTEERDSOEEFEAOCAIVDEN while leaving every code point itself unchanged. Rail Fence is a transposition cipher, not a substitution cipher: it writes each character diagonally down and up across a fixed number of rails, then reads the result row by row from top to bottom. With three rails the row pattern is 0, 1, 2, 1 and repeats with a cycle length of 2(r−1) = 4, so characters land on the top rail at positions 0, 4, 8, 12, 16, 20 and 24, on the middle rail at the alternating positions, and on the bottom rail at positions 2, 6, 10, 14, 18 and 22. Decoding only requires the same rail count and the same starting convention — top rail, no offset, downward first — which the Rail Fence Cipher Decoder uses by default, so the canonical ciphertext above and the original plaintext are both reproduced exactly in your browser.

The Canonical 3-Rail Decoder Example
The phrase WEAREDISCOVEREDFLEEATONCE is the most reused Rail Fence cipher decoder example because it is long enough to show the zigzag clearly but short enough to follow by hand. Number each character with its index from 0 to 24, place the row pattern above it, and the cipher writes itself.
Position: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Letter: W E A R E D I S C O V E R E D F L E E A T O N C E Rail: 0 1 2 1 0 1 2 1 0 1 2 1 0 1 2 1 0 1 2 1 0 1 2 1 0
Row 0 captures positions 0, 4, 8, 12, 16, 20 and 24, which spells WECRLTE. Row 1 captures positions 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 and 23, which spells ERDSOEEFEAOC. Row 2 captures positions 2, 6, 10, 14, 18 and 22, which spells AIVDEN.
Concatenating those three rows in order, top rail first, produces WECRLTE + ERDSOEEFEAOC + AIVDEN = WECRLTEERDSOEEFEAOCAIVDEN, the canonical 3-rail Rail Fence cipher decoder example. Because the algorithm is fully deterministic, the Rail Fence Cipher Decoder returns that exact string when you paste WEAREDISCOVEREDFLEEATONCE with the rail count set to 3, and a round trip with decrypt mode restores the original plaintext character for character. 7 + 12 + 6 = 25 characters, matching the input length, which is a quick sanity check that every code point was accounted for and none was inserted or dropped.
How to Reproduce the Example in the Decoder
- Open the Rail Fence Cipher Decoder page in your browser.
- Switch the mode to Encrypt so the tool writes characters into the zigzag rather than reconstructing it.
- Type the rail count 3 in the rails field. The decoder accepts any whole number from 2 through 100 and rejects fractional or out-of-range values with a clear error.
- Paste the plaintext WEAREDISCOVEREDFLEEATONCE into the input area. Include every space or line break exactly as you want it preserved; the tool iterates Unicode code points rather than stripping non-letters, so what you paste is what gets encoded.
- Click Run and read WECRLTEERDSOEEFEAOCAIVDEN from the result block, with the same whitespace formatting preserved.
- To confirm the round trip, switch the mode to Decrypt, keep the rails at 3, paste the ciphertext back, click Run, and compare the output with the original plaintext. Identical output confirms the convention only, not confidentiality.
Rail Pattern by Rail Count
The rail count determines the row sequence and the cycle length. For any rail count r, the cycle length is 2(r−1), and the same pattern repeats for the entire message. The Rail Fence Cipher Decoder supports 2 through 100 rails.
| Rail count | Cycle length 2(r−1) | Row sequence for one cycle |
|---|---|---|
| 2 | 2 | 0, 1, 0, 1, … |
| 3 | 4 | 0, 1, 2, 1, 0, 1, 2, 1, … |
| 4 | 6 | 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, … |
| 5 | 8 | 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, … |
Reading the same row sequence is what makes the ciphertext recognizable: row 0 collects positions whose index is divisible by 4, row 2 collects positions whose index is 2 mod 4, and row 1 collects the rest. When the rail count equals or exceeds the number of characters, every used position lies on a separate initial descent, so the output equals the input verbatim. Because the transformation is deterministic, identical input and rail count always produce identical output in the Rail Fence Cipher Decoder, which is why the eight golden fixtures on the page can assert the exact ciphertext for each scenario without tolerance.
Trying a 4-Rail Decoder Example
Raising the rail count changes only the cycle length and the row sequence; it never changes which characters are present. With four rails the cycle length grows to 6 instead of 4 and the row sequence becomes 0, 1, 2, 3, 2, 1. The same 25-letter phrase therefore lands on row 0 at positions 0, 6, 12, 18 and 24, on row 3 at positions 3, 9, 15 and 21, and on rows 1 and 2 at the alternating positions in between. Setting the rail count to 4 in the Rail Fence Cipher Decoder and pasting the same plaintext produces a different 25-character ciphertext; switching back to decrypt with the same rail count restores the original phrase exactly. Raising the rail count further up to 100 lets you reproduce any puzzle that publishes its rail count, and the eight golden fixtures the page ships with cover rail counts of 2, 3 and 4 plus an alphabetic phrase, digits, spaces, punctuation and supplementary Unicode so you can verify the convention before trusting any output.
Unicode and Punctuation in a Decoder Example
The Rail Fence Cipher Decoder preserves uppercase and lowercase letters, digits, whitespace, punctuation, and emoji as separate Unicode code points. A Rail Fence cipher decoder example that includes a non-ASCII character is therefore a useful check that the tool is not silently dropping bytes. Emoji such as 👋 count as a single supplementary code point and the tool never splits them into two UTF-16 surrogate halves, so a phrase that includes an emoji, spaces, and punctuation rearranges every code point — including the spaces and the emoji — without losing anything. The copy action writes the exact string the result block displays, line breaks and all, and the interface retains visible formatting inside the result block so you can confirm that whitespace was preserved before pasting the ciphertext back into decrypt mode.
When Two Rail Fence Tools Give Different Output
The Rail Fence algorithm has several common variants, and a Rail Fence cipher decoder example can return different ciphertexts depending on which variant the tool implements. The Rail Fence Cipher Decoder uses a fixed convention — top rail, no offset, downward first, every code point preserved — and locks that behavior in place with eight golden fixtures. Other implementations may strip non-letters, start mid-cycle, begin at the bottom rail, or move upward first, and a reference such as the dCode Rail Fence page documents some of those variants for comparison. The guide on matching the convention walks through how to reconcile mismatches before you trust any output.
| Convention | This tool | Common variants |
|---|---|---|
| Starting rail | Top rail (0) | Sometimes bottom rail |
| Initial offset | None | May start mid-cycle |
| First direction | Downward | Sometimes upward |
| Non-letter handling | Every code point preserved | Often stripped before encoding |
| Case sensitivity | Preserved | Sometimes normalized to upper case |
| Emoji handling | Counted as one code point | May split into surrogate halves |
When two tools disagree, the safest reconciliation is to confirm the conventions first, then re-encrypt under the matching rail count and starting position. Decryption in the Rail Fence Cipher Decoder never guesses a rail count, because guessing belongs to a separate cryptanalysis step. A successful round trip is confirmation of the convention only; Rail Fence is a historical teaching cipher with no secret beyond a small rail count, preserves character frequencies, and is easy to brute force, so it should not be used for credentials, tokens, files or any confidential communication.
If you're weighing options, ROT13 Decoder Online: A CyberChef-Style Browser Tool covers this in detail.