Skip to content
Tezmy Tools

Rail Fence Cipher

Write text in a zigzag over rails and read it row by row

Runs in your browser. Nothing is uploaded.

About the Rail Fence Cipher

The rail fence cipher is a transposition cipher. It writes your message in a zigzag across a set number of rails (rows) and then reads the rows one after the other. The letters stay the same but their order changes. This tool encrypts and decrypts with any number of rails. Type your text and the number of rails and the rail fence cipher appears at once, with a few related figures underneath, and you can copy the result with one tap. The sums run in your browser, so nothing you enter is uploaded.

Updated October 2026

How to use the Rail Fence Cipher

  1. 1Enter your text and the number of rails.
  2. 2Pick the units or options from the menus if the rail fence cipher tool offers them.
  3. 3Read the rail fence cipher in the large result box.
  4. 4Look at the extra rows for related figures.
  5. 5Press Copy result to keep the answer.

When you need the rail fence cipher

It is a staple of puzzle hunts, cipher classes and escape rooms, and a good first step towards understanding transposition ciphers.

The number of rails is the key. Two rails give the weakest result, and more rails scramble the text more, up to the length of the message. With as many rails as letters, the text just comes out in the same order.

    How the rail fence cipher is worked out

    Write letters down the first rail, up to the last and back again in a zigzag. Read each rail from left to right in order to get the ciphertext. WEAREDISCOVEREDFLEEATONCE with 3 rails becomes WECRLTEERDSOEEFEAOCAIVDEN. Decrypting with 3 rails returns the message.

    Every answer on this page comes from that one rule, so you can check any result by hand with a calculator. The figures shown underneath, such as other units, are conversions of the same answer.

    • Both directions
    • Any number of rails
    • Instant result

    Mistakes to avoid with rail fence cipher

    The cipher keeps all the letters, so counts of each letter stay the same. It is easy to break by trying a few rail counts. Spaces count as characters here, so remove them first if you want a puzzle without them.

      On phone and computer

      On a phone, type into the boxes one after another and read the rail fence cipher underneath; Copy result puts it on the clipboard for a message or a note. On a computer the inputs sit on the left and the answer on the right, so you can change one figure and watch the rail fence cipher move. The rail fence cipher works the same on both.

        Checking your rail fence cipher by hand

        A good habit is to test the rail fence cipher with a case you already know. WEAREDISCOVEREDFLEEATONCE with 3 rails becomes WECRLTEERDSOEEFEAOCAIVDEN. Decrypting with 3 rails returns the message.

        If your own figures give a surprising answer, repeat the working yourself: Write letters down the first rail, up to the last and back again in a zigzag. Read each rail from left to right in order to get the ciphertext. Small differences usually come from rounding, from mixing units, or from a typing slip in one of the inputs. Rail fence moves letters rather than replacing them, so compare other ciphers. Try the ROT13 and Caesar Cipher for shifts, the Vigenère Cipher for a keyword, and the Atbash Cipher for a mirror alphabet.

          Features

          • Spaces count as characters
          • Easy to break
          • Choose rails below the message length
          • Clear messages when the rail fence cipher inputs make no sense
          • Copy the result with one tap
          • Private: nothing is uploaded

          Frequently asked questions

          How do I calculate rail fence cipher?

          Write letters down the first rail, up to the last and back again in a zigzag. Read each rail from left to right in order to get the ciphertext. WEAREDISCOVEREDFLEEATONCE with 3 rails becomes WECRLTEERDSOEEFEAOCAIVDEN. Decrypting with 3 rails returns the message.

          What is the formula for rail fence cipher?

          Write letters down the first rail, up to the last and back again in a zigzag. Read each rail from left to right in order to get the ciphertext. The rail fence cipher applies it exactly and rounds only the displayed answer to six significant figures.

          What is a transposition cipher?

          One that reorders letters instead of replacing them.

          How many rails can I use?

          From 2 up to the length of the message.

          Is it secure?

          No. It has only a few possible keys.

          Is this rail fence cipher free and private?

          Yes. It is free, needs no account and runs in your browser, so the numbers you type are not uploaded or stored.

          Related tools