Open Rail Fence and enter WEAREDISCOVEREDFLEEATONCE with 3 rails. Start on the top rail and move downward, with no offset. This 25-letter example lets us follow the whole path without removing any spaces or punctuation.

1. Mark the zigzag

Position123456789
InputWEAREDISC
Rail123212321

The path repeats 1, 2, 3, 2. After reaching the bottom, move straight back to rail 2; do not use rail 3 twice. The fourth letter, R, belongs on the middle rail.

2. Read each rail

RailLettersCount
1WECRLTE7
2ERDSOEEFEAOC12
3AIVDEN6

Read top rail, middle rail, bottom rail

InputWEAREDISCOVEREDFLEEATONCE
Settings3 rails; top start; downward first; zero offset
Expected resultWECRLTEERDSOEEFEAOCAIVDEN
Try this method

The top rail holds 7 letters, the middle holds 12, and the bottom holds 6: 25 altogether. Blank grid positions help you see the zigzag. They are not spaces to copy into the ciphertext.

3. Reconstruct the rails

  1. Draw the same 25-position zigzag, leaving the letters out.
  2. Fill rail 1 with the first 7 ciphertext letters.
  3. Fill rail 2 with the next 12 letters and rail 3 with the final 6.
  4. Follow the zigzag from the top, taking the next letter from each rail you visit.

Reading along the rebuilt zigzag returns WEAREDISCOVEREDFLEEATONCE. Three equal chunks would put letters on the wrong rails. Work out the rail lengths from the message length and the chosen path first.

Your turn

Use the same three-rail path for ABCDEFG. Write the contents of each rail before joining them.

Continue the lesson

Rail Fence cipher toolPrint Rail Fence grid practiceSubstitution vs. transpositionMake a two-stage puzzle and answer key