What the Rail Fence Cipher does
The rail fence cipher writes your message in a zig-zag across a number of rails, then reads the rails off one by one. It is a transposition cipher: the letters never change, only their order does. It works entirely in your browser: you type or paste text, and the result appears at once, with nothing uploaded and nothing stored. People searching for a rail fence cipher usually want exactly that — a quick answer without an account, a download, or a wait.
Puzzle fans solving classic transposition puzzles, students learning the difference between substitution and transposition, and teachers who need a cipher that can be worked on paper with a pencil and a fence of lines. Students use it for homework and puzzles, developers use it at work, and writers use it when a deadline is close. The common thread is simple: the job is small, the answer should be instant, and the text should stay private.
This page keeps that promise. The rail Fence Cipher runs on your own device, so your words never leave the tab. You can use it as often as you like, on any text, and close the page knowing nothing was saved anywhere — there is no history, no log, and no sign-up standing between you and the answer.
If you have never used a tool like this before, start with the example on this page and change one thing at a time — one word, one setting — and watch the result change. That is the fastest way to learn what each input does, and it works for every tool in this family, because they all follow the same pattern: text in, result out, nothing saved.
The method behind the Rail Fence Cipher
The message is written diagonally, bouncing between the top rail and the bottom rail like a fence. With 3 rails, the first letter goes on rail 1, the second on rail 2, the third on rail 3, the fourth back on rail 2, the fifth on rail 1, and so on. The ciphertext is the rails read in order: all of rail 1, then rail 2, then rail 3. Spaces are removed before encoding, since they would give the pattern away. The rule this page uses is: Write the letters in a zig-zag across the chosen number of rails, then read each rail in turn from top to bottom. Decryption rebuilds the zig-zag pattern and reads it back in order.
The cipher is weak by design: the letters never change, so a codebreaker who guesses the rail count can read the message by laying the letters back into the zig-zag. With only a few sensible rail counts to try — 2 to 10 — a short message falls quickly, which is exactly why it is a good teaching cipher and a poor secret-keeper.
Because the rule never changes, the same input always gives the same output. Run the example below twice and the result will match exactly, character for character. That predictability is what makes the tool useful for checking your own work. For a different kind of text job, the ROT13 encoder covers the next step once you have your result. The comparison section further down this page explains which of the two fits which job, so you can pick before you paste.
The rule above is the whole method — there is no hidden step and no second pass. What you see in the rule is what the tool computes, which is why the worked example below can be followed by hand, one step at a time, with a pencil if you like.
The number of rails, explained
The number of rails is the whole key. Two rails make a simple back-and-forth, three rails make the classic zig-zag, and more rails make a longer, flatter pattern. The tool accepts 2 to 10 rails; more than that on a short message leaves most rails nearly empty, which makes the pattern obvious.
With 3 rails, 'HELLO WORLD' becomes 'HOLELWRDLO'. The spaces are removed first, so the ten letters HELLOWORLD zig-zag across the rails and are read off rail by rail. With 2 rails the same message becomes 'HLOOLELWRD' — a shorter zig-zag, but a different result.
If you are setting a puzzle, 3 rails is the sweet spot: 2 rails is too easy to spot, and 5 or more on a short message leaves a tell-tale pattern of mostly-empty rails. Agree the rail count with the reader first, or they cannot decode it.
When in doubt, try the worked example below first — it uses the page defaults, so it shows the tool working exactly as it ships.
Paste from anywhere — a document, a chat, a web page. The tool reads only the text you give it, so stray formatting, links, and images are left behind. If the pasted text looks odd, paste it as plain text first and then copy it in, so nothing invisible rides along.
A worked example
Take this input: 'HELLO WORLD' with 3 rails, encrypting. The spaces are removed, leaving HELLOWORLD. The letters zig-zag across 3 rails: rail 1 takes H, O, L; rail 2 takes E, L, W, R, D; rail 3 takes L, O. Reading the rails in order gives HOL, then ELWRD, then LO. The result is 'HOLELWRDLO' — 10 characters, with the rail count shown as 3.
Decrypt 'HOLELWRDLO' with 3 rails and you get 'HELLOWORLD' back. The space is not restored — the cipher removes spaces before encoding, so the decoded text runs together.
Try 2 rails on the same message: the letters split into HLOOL on rail 1 and ELWRD on rail 2, giving 'HLOOLELWRD'. The same ten letters, a different rail count, a different result — which shows why the rail count is the key.
You can check the result yourself without trusting the page. Reverse the operation — decrypt what you encrypted, or run the output back through the tool with the opposite setting — and the original input should come back. If it does not, the first thing to check is the input: a missing letter, an extra space, or a setting that changed between the two runs.
Who uses a Rail Fence Cipher — and why
A puzzle setter encodes a clue with 3 rails and prints it as a single block of letters, so solvers must work out the rail count before the message appears. It is the kind of job that comes up often enough to remember, and rarely enough to justify installing anything for.
A teacher shows the difference between substitution and transposition by encoding the same message with a letter-substitution cipher and then with the rail fence — one changes letters, the other changes order. The word counter is the natural next stop when the result needs a different treatment. It answers the question this page leaves open, so the two together cover the whole job.
A student checking homework lays the ciphertext back into a zig-zag on paper and reads the message off diagonally to confirm the decoding.
Rail Fence Cipher vs Text Reverser
The text reverser reverses every character, while the rail fence reorders letters by a zig-zag. One reverses; the other weaves, and both keep every letter exactly as it was. The text reverser is the closest comparison on this site, and the two answer different questions. Both are free, both run in your browser, and neither asks for an account.
Pick the rail Fence Cipher when you want a transposition cipher where the letters stay the same and only their positions move. Pick the text reverser when you want every character reversed, letters included.
In practice most people keep both bookmarked. They are small, free, and private, and switching between them costs nothing — paste the same text into each and compare the outputs side by side before deciding which one fits the job in front of you. The habit that saves the most time is deciding the job first and the tool second: once you know whether you need a cipher, a conversion, or a count, the choice between two similar tools is usually obvious.
Mistakes to avoid with a Rail Fence Cipher
Forgetting that spaces are removed before encoding. The decoded message comes back without spaces, so 'HELLO WORLD' decodes as 'HELLOWORLD' — that is not an error, it is how the cipher works.
Using too many rails for a short message. With 8 rails on a 10-letter message, most rails hold a single letter and the pattern is obvious at a glance.
Not telling the reader the rail count. The ciphertext alone does not say how many rails were used, so the reader has to guess — agree the count first. Mixing up encryption and decryption. Decryption rebuilds the zig-zag from the ciphertext; encrypting twice does not undo it, it scrambles the message further. The fix in every case is the same: check the input, check the setting, and test with the worked example before trusting a long result.
If the result still looks wrong after checking the input, run the worked example exactly as written. If the example works and your input does not, the difference is in your input — compare them character by character, including spaces, until the odd one out shows itself.
How to use this Rail Fence Cipher
Type your message, set the number of rails, and choose Encrypt or Decrypt. The result appears live, and switching direction with the same rail count turns ciphertext back into the original message. The case converter can help with the next step once you have your output.
Work a short message by hand first — draw three lines, write the letters in a zig-zag, and read the rails off. If your hand result matches the tool, you understand the cipher. Keep the rail count with the message, or the reader cannot decode it.
The result can be copied with the buttons above it, or shared and printed from the actions on the page. If you use the tool often, bookmark the page — the address never changes, and your last input is not saved, so a fresh visit always starts clean. That also means there is nothing to clear and nothing to log out of when you are done.
Everything on this page is free, with no account and no limit on how often you use it. Your text is processed in your browser and never sent to a server, so drafts, names, and private notes stay on your device. If the result looks wrong, check the input first — a stray space or a missing character is the cause far more often than the tool itself.