Skip to main content

Character Frequency Counting: From Cipher Cracking to Cleaner Text

How counting each character in text powers cryptanalysis, data cleaning, and linguistics, plus why E is English's most common letter and how case sensitivity changes the math.

Published By Li Lei
#character frequency #frequency analysis #cryptanalysis #text analysis #data cleaning

Character Frequency Counting: From Cipher Cracking to Cleaner Text

Counting how often each character shows up in a block of text sounds almost too simple to be useful. You tally every letter, space, and symbol, then sort the tally from most common to least. That is the whole idea. Yet this one operation sits under cryptanalysis, data cleaning, and a surprising amount of linguistics. The character frequency counter does the tallying for you and reports both the raw count and each character's share of the whole as a percentage, so you read the numbers instead of squinting at the text.

This post walks through what the count actually tells you, where it earns its keep, and the two settings (case folding and whitespace) that quietly change every answer.

What the count actually measures

For each text you feed it, the tool produces one row per distinct character: the character itself, how many times it appears, and what percentage of all characters it represents. Counting happens by Unicode code point, which matters more than it first appears. An emoji counts as one character rather than two surrogate halves, and a Chinese ideograph counts as one unit rather than being split. So a "character" here means a real symbol a reader would point at, not a byte or a code unit.

The percentage column is the part people underuse. A raw count of 40 for the letter e means one thing in a 200-character note and something else entirely in a 4,000-character article. The share tells you how dominant a character is regardless of length, which is exactly what you need when comparing two different texts.

A worked example

Take the short string the cat sat. Run it through with whitespace counting turned on and case folding left at its default, and you get this ranking:

  • t appears 3 times (27.3%)
  • a appears 2 times (18.2%)
  • space appears 2 times (18.2%)
  • h appears 1 time (9.1%)
  • e appears 1 time (9.1%)
  • c appears 1 time (9.1%)
  • s appears 1 time (9.1%)

Eleven characters total, seven of them distinct. Notice the space sits near the top. In ordinary prose the space is one of the most frequent characters of all, which is why it muscles letters down the list. Turn whitespace off and the same string collapses to a clean letter ranking led by t, then a, then everything else tied at one. That single toggle is the difference between studying the text and studying the gaps in it.

Why E rules English, and how that breaks ciphers

The headline fact of English letter frequency is that E is the most common letter, at roughly 12.7% of typical text, followed by T, A, O, I, N, S, H, R. That ordering is the foundation of frequency analysis, the oldest practical technique in code breaking.

Here is why it works. A Caesar cipher shifts every letter by a fixed amount, and a simple substitution cipher swaps each letter for another consistently. Neither one changes how often a letter appears; it only changes which letter wears the mask. So if you count the ciphertext and the runaway most common character is, say, K, your strongest first guess is that K is standing in for E. Line the rest of the ciphertext ranking up against the English order e t a o i n and the substitution starts to fall out, letter by letter.

For a Caesar specifically, finding the shift that maps the top ciphertext letter back to E usually hands you the entire key. If you want to generate practice ciphertext to attack this way, or confirm a shift after frequency analysis points at one, pair the counter with the Caesar cipher encoder. The workflow is: encode a message, count the result with spaces and punctuation switched off, watch E's stand-in float to the top, and read the shift straight off the ranking.

I tested this on myself before trusting it. I shifted a paragraph of plain English by seven positions, pasted the gibberish into the counter with whitespace and punctuation stripped, and the top row was a single letter at about 11%. It was the encoded E. Lining the next few rows against e t a o i n confirmed the shift in under a minute, faster than I could have reasoned it out by staring at the letters. The percentage column did the work: the peak was sharp enough that I never doubted it.

Beyond cryptography: cleaning, auditing, hidden whitespace

Frequency counting earns its place in plenty of non-secret work too.

Finding hidden whitespace. Stray tabs, double spaces, and rogue newlines are invisible until something counts them. Turn whitespace counting on and every tab, space, and line break gets its own labeled row, so you see at a glance that a "clean" file is actually riddled with trailing tabs. That is often the first clue when a CSV import misbehaves or two strings that look identical refuse to match.

Auditing the character mix of a string. Designing a slug format, a coupon code scheme, or a password policy? Paste a few hundred real examples and read the ranking. If one separator turns up in 30% of positions, that is a pattern worth standardizing rather than leaving to chance. The count surfaces structure you would never notice by scanning.

Data cleaning. Before you parse a field, knowing which characters live in it tells you what to guard against. An unexpected non-breaking space, a smart quote where a straight quote should be, or a zero-width character all show up as their own rows once you count by code point. To then strip the duplicate lines you find, hand the cleaned text to the text deduplicator.

Case sensitivity changes everything

By default the counter folds case, so A and a land in the same row. For plain letter-frequency work that is what you want: you care that the letter E is common, not whether a particular instance was capitalized. Folding keeps the signal clean.

But the moment capitalization itself is the thing you are measuring, folding hides the answer. Auditing an all-caps headline, checking how heavily a style leans on uppercase, or analyzing case patterns in passwords all require the case-sensitive switch turned on, which splits HELLO and hello into different rows. Forgetting this is the most common mistake I see: people study uppercase usage with folding still on and quietly add their capitals and lowercase letters into one merged total. Flip the switch first.

A quick checklist before you read the ranking

  • For letter-frequency or cipher work, turn whitespace counting off so the space does not crowd the top.
  • For finding hidden tabs and newlines, turn it on so nothing stays invisible.
  • Studying capitalization? Turn case sensitivity on before you read a single number.
  • Comparing two texts of different lengths? Read the percentage column, never the raw count.

Counting characters is humble math, but it is the lens that makes a cipher transparent, a dirty file legible, and a language's texture measurable. Once you know E carries 12.7% of English and that a single toggle decides whether you are counting letters or counting the spaces between them, the ranking stops being a table of numbers and starts being an answer.


Made by Toolora · Updated 2026-06-13