TL;DR —
LEN(text)returns the number of characters in a value — letters, digits, punctuation, and every space and invisible character. That "every character" part is the whole point:LENis the debugger for text. When"Apple"won't match"Apple",=LEN(A2)returning 6 instead of 5 tells you there's a trailing space you couldn't see. Beyond counting, it drives validation, the famous occurrence-counting trick, and length-based extraction.
=LEN("Apple") ' -> 5
=LEN("Apple ") ' -> 6 (the trailing space is real — now you can see it)
=LEN(A2)<>9 ' TRUE flags account numbers that aren't 9 characters
=LEN(A2)-LEN(SUBSTITUTE(A2,",","")) ' how many commas are in A2
LEN is the humblest function in Excel and one of the most useful, because it's
the one that makes invisible problems visible. Every "these two cells look
identical but won't match" mystery ends with a LEN that comes back one bigger
than you expected.
What you'll learn
- Why
LENcounts everything — and how that makes it a diagnostic tool - Using
LENto validate fixed-width IDs, codes, and account numbers - The
LEN-minus-LENtrick for counting occurrences of a character - Driving
LEFT/RIGHT/MIDwith a lengthLENcomputes - Why
LENignores number formatting — and when you needLENB
The mental model: LEN is a ruler, not a reader
LEN doesn't understand your text — it just measures it. It lays a ruler along
the string and reports how many characters are there, making no distinction
between a visible letter and an invisible trailing space. That indifference is
precisely what makes it valuable. Your eyes skip whitespace; LEN doesn't.
So the primary use of LEN isn't "how long is this word." It's "is this cell
what I think it is?" When something downstream misbehaves — a lookup misses, a
comparison fails, an ID looks valid but is rejected — LEN is the first probe:
=LEN(A2) ' expected 5, got 6? -> hidden character. Now go find it.
Pair it with TRIM to confirm the
diagnosis: if =LEN(A2) is 6 but =LEN(TRIM(A2)) is 5, the extra character was
a normal space. If TRIM doesn't bring it down, you've got a CHAR(160) or a
control character — go check with =CODE(...).
Validation: catching bad data by its length
A huge amount of real-world data has a known length — a 9-digit account
number, a 3-letter currency code, a 13-character invoice ID, a 16-digit card.
LEN turns that expectation into a filter:
=LEN(A2)<>9 ' flag account numbers of the wrong length
=IF(LEN(A2)=3, "ok", "check") ' currency codes must be exactly 3 letters
=SUMPRODUCT(--(LEN(A2:A100)<>13)) ' how many invoice IDs are malformed?
This catches a whole class of import errors — a digit dropped, a code truncated,
a stray character appended — that no amount of eyeballing will reliably find.
Length is a cheap, strong integrity check, and LEN is how you apply it across a
column at once. Wrap it in Conditional Formatting to light up the bad rows.
The classic trick: count occurrences with LEN
The most reused LEN idiom has nothing to do with length directly. To count how
many times a character appears in a cell, remove it with
SUBSTITUTE and measure how much shorter the
string got:
' how many commas in A2?
=LEN(A2) - LEN(SUBSTITUTE(A2, ",", ""))
' how many words? (single-spaced text: spaces + 1)
=LEN(TRIM(A2)) - LEN(SUBSTITUTE(TRIM(A2), " ", "")) + 1
Every comma you delete shortens the string by one, so the difference is the count. It's the kind of lateral idea that, once it clicks, you'll reach for again and again — counting delimiters before a split, counting words, sanity- checking a CSV field.
Driving extraction: LEN computes "how much"
LEN is the arithmetic behind dynamic
LEFT/RIGHT/MID extraction, where the amount
to take isn't fixed but depends on the string:
' everything except the last 4 characters
=LEFT(A2, LEN(A2) - 4)
' strip a known 3-character prefix like "ID-"
=RIGHT(A2, LEN(A2) - 3)
' the file extension after the last dot (paired with FIND/SUBSTITUTE)
=RIGHT(A2, LEN(A2) - FIND("~", SUBSTITUTE(A2, ".", "~", LEN(A2)-LEN(SUBSTITUTE(A2,".","")))))
Whenever you catch yourself hard-coding a character count into LEFT/RIGHT,
ask whether LEN(A2) - something expresses it more robustly — it survives rows
of different lengths, where a hard number silently truncates.
The gotcha: LEN sees the value, not the format
A frequent surprise: LEN measures the underlying value, not what the cell
displays. Number formatting — currency symbols, thousands separators, decimal
places, dates shown as text — is a display layer that LEN ignores:
=LEN(1000) ' -> 4, even if the cell shows "$1,000.00"
=LEN(0.5) ' -> 3 ("0.5"), even if shown as "50%"
=LEN(TODAY()) ' -> 5 (the serial number, e.g. "46204"), not "2026-07-06"
If you need the length of the displayed string, convert it to text first with
TEXT: =LEN(TEXT(A2, "$#,##0.00")). And for
double-byte text — Japanese, Chinese, Korean — know that LEN counts each
character as 1, while LENB counts bytes (often 2 per CJK character); use
LENB when a downstream system measures in bytes.
The judgment call
LEN earns its place two ways. As a diagnostic, it's the first thing to
reach for when text "looks right but acts wrong" — an unexpected count is proof
of hidden characters, and it points you at TRIM/CLEAN. As a building
block, it powers validation (LEN(A2)<>n), counting (LEN-minus-LEN), and
dynamic extraction (LEN(A2)-k). What it is not is a way to measure a
formatted display — for that, format to text first. Keep those two roles
straight and LEN becomes the small tool you use ten times a day.
How ExcelMaster helps
When a lookup fails on values that look identical, the fix starts with a
diagnosis most people skip — is the length what it should be? ExcelMaster
runs that check for you: it compares LEN against LEN(TRIM(...)), identifies
the hidden character by its code, and writes the cleanup that makes the match
work. And when you need length-driven extraction or validation across a whole
column, it builds the LEN-based formula rather than leaving you to count
characters by hand. Describe the symptom; it measures, diagnoses, and fixes.
Frequently asked questions
What does the LEN function do in Excel?
LEN(text) returns the number of characters in a value, counting letters,
digits, punctuation, spaces, and even invisible characters. =LEN("Apple")
returns 5. Its most valuable use is diagnostic: an unexpected count reveals
hidden trailing spaces or non-printing characters.
Does LEN count spaces?
Yes — LEN counts every character, including leading, trailing, and interior
spaces, plus non-printing characters like CHAR(160). That's why =LEN("Apple ")
returns 6, not 5, and why LEN is the tool for detecting whitespace you can't
see.
How do I count how many times a character appears in a cell?
Subtract the length after removing it: =LEN(A2)-LEN(SUBSTITUTE(A2,",",""))
counts the commas in A2. Removing every instance shortens the string by the
number of instances, so the difference is the count.
Why does LEN return the wrong length for a formatted number?
LEN measures the underlying value, not the displayed format. =LEN(1000) is 4
even when the cell shows $1,000.00, because the currency symbol and separators
are formatting, not data. To count the displayed characters, convert with TEXT
first: =LEN(TEXT(A2,"$#,##0.00")).
What's the difference between LEN and LENB?
LEN counts characters (each counts as 1). LENB counts bytes, where
double-byte characters — Japanese, Chinese, Korean — count as 2. Use LENB only
when a downstream system measures string length in bytes; for normal character
counts, use LEN.
Tested in
Tested in: Excel 365 (Windows 11) — last verified 2026-07-06.
Related guides: Excel TRIM & CLEAN · Excel SUBSTITUTE & REPLACE · Excel LEFT, RIGHT & MID · Excel UPPER, LOWER & PROPER
