Reference

The Rail Fence Cipher Explained

The rail fence cipher does not change any letters, it only reorders them. Writing a message in a zigzag across a chosen number of rails, then reading the rails off one at a time, produces text that looks scrambled but contains every original letter.

Last updated 14 July 2026

Want to try it? Open the Rail Fence Cipher translator and encode or decode your own text in your browser.

Writing the zigzag

Picture the message bouncing down and up across a fixed number of horizontal rails, one letter per step: down to the bottom rail, back up to the top, and repeat until the message runs out.

The number of rails is the only key. More rails spread letters further apart before they land back on the same row, but very short messages stay easy to read no matter how many rails you pick.

Why it is easy to break

A message encrypted with the rail fence cipher keeps the same letters in the same overall frequency as ordinary text, so counting letters gives no clues. Instead, an attacker just tries every reasonable rail count and looks for one that reads as real words.

Because there are rarely more than 20 or 30 sensible rail counts to try, brute-forcing the rail count is quick even by hand, which is why the rail fence cipher is a teaching example rather than real protection.

Frequently asked questions

How do you break a rail fence cipher without the key?

Try every reasonable number of rails, rebuild the zigzag for each one, and read off the result. With a short ciphertext this brute-force search finds the correct rail count in moments.

Is rail fence a substitution or transposition cipher?

Transposition. It never changes what a letter is, only where it sits in the message, which is the opposite approach from substitution ciphers like Caesar or Vigenere.

Keep exploring