Cryptography & Security
Basic

Caesar Cipher Shift

Shift each letter forward by k positions.

Formula

c=(m+k) mod 26c = (m + k) \bmod 26

Variables

cCipher letter (0–25)
mPlain letter (0–25)
kShift

Example

m=0 (A), k=3: c = 3 (D)

How it works

This formula describes how a Caesar cipher turns a plaintext letter into a ciphertext letter by moving it forward a fixed number of places in the alphabet. The letters are treated as numbers from 0 to 25, so adding the shift k moves the position, and the modulo 26 wraps around when you pass Z. That wraparound is what makes the alphabet cycle back to the beginning instead of running out of letters.

When to use it

Use this when encoding or decoding a simple Caesar cipher in cryptography lessons, puzzles, or introductory programming exercises. It also helps when you need a quick way to model letter shifting with circular counting.

Worked example, step by step

Let m = 22 (W) and k = 5 c = (m + k) mod 26 c = (22 + 5) mod 26 c = 27 mod 26 c = 1 So the ciphertext letter is 1, which corresponds to B.

Common mistakes to avoid

  • Forgetting to apply mod 26 and ending up with numbers bigger than 25
  • Mixing up the letter-to-number mapping, such as using A = 1 instead of A = 0 without adjusting the formula
  • Shifting in the wrong direction when encoding or decoding

Did You Know?

Julius Caesar shifted letters by three to protect military messages over two thousand years ago.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026