← All blog posts

Character Counter formula — how it actually works

WhiteUI · A plain-English guide to the Character Counter

Every count on the Character Counter comes from one short set of rules. The tool takes your text, measures it four ways, and shows the four numbers. The rules below are the whole method, and the worked examples show each one in action.

Characters (with spaces) = every character, including spaces
Characters (without spaces) = characters after removing all whitespace
Words = words after trimming, split on whitespace
Lines = text split on line breaks

At a glance

10 of 17 characters are not spaces10 letters7 spaces“ Hello world ” has 7 whitespace characters
The text “ Hello world ” has 17 characters, of which 10 are letters and 7 are spaces.

Characters with spaces: the length of the text

The with-spaces count is the length of the text, character by character. “Hello, world!” is 13 characters, because the comma and the exclamation mark each count as one. The default two-line sample is 36 characters: 13 for the first line, 1 for the line break, and 22 for the second line.

Characters without spaces: take the whitespace out

The without-spaces count removes every whitespace character first — spaces, tabs and line breaks — and then measures what is left. The default sample goes from 36 to 30, because it holds 6 whitespace characters: 5 spaces and 1 line break. A tab is one whitespace character too: “Name:” followed by a tab and “Satish” is 12 characters with spaces and 11 without.

Words: trim, then split on whitespace

Words are counted by trimming the ends of the text and then splitting on runs of whitespace, so any number of spaces in a row still marks one gap between words. “ Hello world ” has 2 leading spaces, 3 spaces in the middle and 2 trailing spaces, yet it counts as 2 words, not 8. The text is 17 characters and 10 without spaces, and the 7 whitespace characters are the difference between the two counts.

Lines: split on line breaks

Lines are counted by splitting the text on line breaks, so each break starts a new line. “Line one”, “Line two” and “Line three” count as 3 lines. But a trailing line break leaves an empty line after it: “One”, “Two” and “Three” followed by a final line break read as 4 lines, not 3. The same text is 14 characters, 11 without spaces and 3 words, and without the trailing break it is 13 characters and 3 lines.

Worked example: check the maths yourself

Take the default sample and count it by hand. The first line, “Hello, world!”, is 13 characters. The line break is 1. The second line, “This is a second line.”, is 22. Add them: 13 + 1 + 22 = 36. The spaces are 1 in the first line and 4 in the second, plus the line break, which is 6 whitespace characters, and 36 − 6 = 30. The words are 2 in the first line and 5 in the second, which is 7. If your hand count lands on 36, 30, 7 and 2, you have the method right.

The common mistake

People count words by counting spaces and adding 1, which only works when every gap is exactly one space. “ Hello world ” has 7 whitespace characters, so spaces plus 1 gives 8 words, but the true count is 2. Count words by splitting on runs of whitespace, or let the tool do it, and the double spaces stop fooling you.

Frequently asked questions

What is the formula for characters without spaces?

Take the full character count and subtract every whitespace character. For the default text, 36 minus 6 is 30.

How are words counted?

The text is trimmed, then split on runs of whitespace. “ Hello world ” counts as 2 words, not 8.

Why does a trailing line break add a line?

Lines are counted by splitting on line breaks, so “One”, “Two” and “Three” with a final break give 4 lines: the break leaves an empty fourth line.

Does a tab count as whitespace?

Yes. “Name:” plus a tab plus “Satish” is 12 characters with spaces and 11 without, because the tab is one whitespace character.

More guides on the Character Counter

Try it yourself

Try the Character Counter — free, in your browser.

Open the Character Counter