# Rail Fence Cipher > Encode and decode the rail fence (zigzag) cipher with 2 to 10 rails, see the zigzag drawn out, or crack a message when you do not know the key. - Page: https://linguaholic.com/tools/rail-fence-cipher/ - Type: free online tool (Converters & translators), no sign-up, runs in the browser - Publisher: Linguaholic (https://linguaholic.com/), made by Marcel Iseli - Last updated: October 3, 2026 - Open it pre-filled: https://linguaholic.com/tools/rail-fence-cipher/?text=HOLELWRDLO&mode=decode&open=crack - `text`: text to encode or decode (for example `HELLOWORLD`) - `mode`: direction: encode (default) or decode (for example `decode`) - `rails`: number of rails, 2-10 (clamped); default 3 (for example `3`) - `open`: open a section: crack (every rail count from 2 to 10 ranked), steps (the zigzag drawn out), frequency (letter counts) or identify (which cipher is this?) (for example `crack`) ## What is the rail fence cipher? The **rail fence cipher**, also called the **zigzag cipher**, hides a message by changing the order of its letters, not the letters themselves. You write the message in a zigzag across a number of rows, the “rails” of the fence, and then read the rows one after the other. With 3 rails, **MEETATTHEPARKATNOON** becomes `MAEKOETTHPRANOETATN`. That makes it a **transposition cipher**. Ciphers like the [Caesar cipher](https://linguaholic.com/tools/caesar-cipher/) swap each letter for another one (substitution); the rail fence keeps every letter and only moves it. You can see the difference at a glance: a rail fence cipher text has exactly the same letters as the original, just scrambled. ## How to use the rail fence cipher encoder and decoder 1. Choose **Encode** or **Decode**. 2. Set the number of **rails** (the key). Both sides have to use the same number. 3. Type or paste your text. The result updates as you type, and the zigzag view in the tool shows where every letter lands on the fence. 4. Tap **Copy** to save the result. Do not know the number of rails? The tool can crack it for you: it tries every number of rails from 2 to 10, so you only have to spot the result that reads as real words. The section on cracking below explains why that works so well. ## Frequently asked questions **What is the rail fence cipher?** The rail fence or zigzag cipher writes a message diagonally down and up across a number of rows, called rails, then reads the rows one after another. It changes the order of the letters but not the letters themselves. **How do you encode a rail fence cipher?** Write the first letter on the top rail and each next letter one rail lower, turning back up at the bottom rail and down again at the top. Then read the top rail left to right, followed by each rail below it. **How do you decode a rail fence cipher?** Rebuild the fence: mark the zigzag positions for the message length, count how many letters fall on each rail, cut the cipher text into those lengths, fill each rail, and read the zigzag again. The tool does this when you choose Decode and set the rails. **How do you decrypt a rail fence cipher without the key?** Try every number of rails. A message can only use 2 up to one less than its length, and short messages almost always use 2 to 6, so only one attempt will read as words. The tool's crack option tries 2 to 10 rails for you. **How many rails should I use?** Three is the classic choice. More rails scramble a short message more, but the sender and receiver must use the same number, because the number of rails is the key. **What is the cycle of a rail fence cipher?** The zigzag repeats every 2 x (rails - 1) letters. On 3 rails the cycle is 4, which is why a key is sometimes written as height 3, cycle 4. **Is the rail fence a substitution or a transposition cipher?** It is a transposition cipher: every letter stays the same and only moves. A rail fence cipher text therefore has normal English letter frequencies, which helps you recognize it. **Does the rail fence cipher keep spaces?** Most puzzles remove spaces before encoding so word lengths do not give the message away. If you keep them, they are treated as characters and land on the fence like letters. **Is the rail fence cipher secure?** No. It has very few possible keys, so anyone can try them all in a minute. It is a great way to learn how transposition ciphers work. ## Data sources The code breaker's English letter frequencies and word checks come from Linguaholic’s English dictionary, built from the open ENABLE and SCOWL word lists. Licenses and notices: https://linguaholic.com/tools/data/dict/v1/NOTICE.txt ## Related tools - [Caesar Cipher](https://linguaholic.com/tools/caesar-cipher/): Encode and decode the Caesar shift cipher with any shift from 1 to 25, or crack a message without the key: every shift is tried and ranked for you. - [Vigenère Cipher](https://linguaholic.com/tools/vigenere-cipher/): Encode and decode the Vigenère cipher with a keyword, or crack a message without the key: the tool finds the key length and the keyword for you. - [Substitution Cipher](https://linguaholic.com/tools/substitution-cipher/): Encode and decode with any cipher alphabet or keyword, or paste a cryptogram and let the solver crack it; then fix any letter yourself. - [Atbash Cipher](https://linguaholic.com/tools/atbash-cipher/): Encode and decode the Atbash cipher, which swaps each letter with its mirror (A↔Z, B↔Y), with the alphabet chart, step-by-step working and examples. - [Polybius Square](https://linguaholic.com/tools/polybius-square/): Decode and encode the Polybius square cipher, which turns each letter into its row and column in a 5×5 grid (I and J share a cell). - [Morse Code Translator](https://linguaholic.com/tools/morse-code-translator/): Translate text to Morse code and decode it back, hear it as adjustable-speed sound with a visual flasher, and read the full Morse alphabet, number, and punctuation chart.