Rail Fence Cipher Encoder & Decoder
Encode and decode the rail fence cipher — a transposition cipher that writes text in a zig-zag across a set number of rails, then reads it off row by row.
What is the rail fence cipher?
The rail fence cipher is a transposition cipher: instead of replacing letters, it rearranges them. You write the message in a zig-zag down and up across a set number of rows, or "rails," then read each row left to right to get the cipher text.
How to use it
- Choose Encode or Decode.
- Set the number of rails.
- Type your text and copy the result.
How the rail fence works
Picture the letters bouncing between the top and bottom rails in a zig-zag. Reading the rails top to bottom scrambles the order. The number of rails is the key: the sender and receiver must agree on it, and decoding rebuilds the zig-zag to restore the original order. The letters themselves never change, only their positions.
Where it is used
The rail fence is a great teaching example of transposition and a common step in multi-stage puzzles and escape-room clues.
More codes and ciphers
Explore the rest of the family: the Caesar Cipher, Atbash, Vigenère, and A1Z26. For other encodings, try the Morse Code Translator and the Binary Translator.
Free and private
This rail fence cipher tool runs entirely in your browser — free, with no sign-up, and nothing you type is uploaded or stored.
Frequently asked questions
- What is the rail fence cipher?
- The rail fence cipher is a transposition cipher: you write the message diagonally down and up across a number of 'rails' (rows), then read each row left to right to get the cipher text. It rearranges letters rather than replacing them.
- How do I decode a rail fence cipher?
- Choose Decode and set the same number of rails used to encode it. The tool rebuilds the zig-zag pattern and reads the letters back in the original order.
- How many rails should I use?
- Any number from 2 upward. More rails scramble short messages more, but the sender and receiver must agree on the exact rail count, since it is the key.
- Is it free and private?
- Yes — it runs entirely in your browser with no sign-up, and nothing you type is uploaded.
More free tools
- Morse Code TranslatorTranslate 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.
- Roman Numeral ConverterConvert numbers to Roman numerals and back, turn any date into Roman numerals for tattoos, and read the full chart from 1 to 1000.
- Binary TranslatorTranslate text to binary code and back, convert between decimal and binary numbers, and read the full binary alphabet chart.
- NATO Phonetic AlphabetSpell any word or name in the NATO phonetic alphabet (Alpha, Bravo, Charlie…), hear it read aloud, and browse the full chart with pronunciations, numbers, and the police alphabet.
- Braille TranslatorTranslate English text to Grade 1 Braille and Braille back to text, and read the full Braille alphabet and number chart.
- Hex to TextConvert hexadecimal to readable text and text to hex instantly, both directions, with a full hex ASCII reference chart. Private and works offline.