What is character frequency?
Character frequency is a count of each character in a piece of text, often shown as a percentage of the total. Letter frequency is the same idea limited to letters.
Why it matters
Frequency analysis breaks simple substitution ciphers, because each plaintext letter always maps to the same cipher letter and keeps its frequency. Compression methods such as Huffman coding give shorter codes to common characters. Linguists use frequency to compare languages, and developers use it to inspect data.
English letter order
In ordinary English text, the most common letters are roughly E, T, A, O, I, N, S, H and R. Exact figures vary with the sample, so treat any table as an average.
How to count it
By hand, write each character once and add a tally mark every time you see it. In code, a counter does the job:
from collections import Counter
text = "hello world"
print(Counter(text).most_common())The result lists each character with its count, most common first.
Common uses in practice
- Breaking classical ciphers and solving puzzles
- Detecting the language of a text
- Checking data for unexpected characters
- Designing compression codes
Tips for accurate results
Use a large sample, decide in advance whether case and spaces matter, and clean the text if it contains markup. Remember that frequencies describe a sample, not a rule for every sentence.
Try it
Count your own text with the character frequency counter, compare against English with the letter frequency counter, or view an A to Z table with the by-letter page.
Count it instantly. Paste your text and see every character ranked by frequency.
Open the character frequency counter or try the letter frequency counter.