LEN Function in Excel — Count Characters & Detect Invisible Junk (2026) | Sheets & Cells
Text · Cleanup Trio

LEN Function in Excel

Returns the number of characters in a text string, spaces included. Looks trivial — is anything but. LEN validates fields, detects invisible junk before your users see it, and powers the elegant "count occurrences" trick that Excel doesn't otherwise offer.

Universal Support
LEN has existed in Excel since Excel 1.0 (1985). Works identically in Excel 2003, 2007, 2010, 2013, 2016, 2019, 2021, Microsoft 365, Excel Online, Excel Mobile, Google Sheets, and LibreOffice Calc. No compatibility caveats.

The Character-Count Detective

Two strings that look identical on-screen. LEN reveals which one is silently broken.

Real scenario: Your CRM export has 500 customer names. Some rows have trailing spaces, some have CHAR(160) non-breaking spaces from a Word paste, some are perfectly clean. On-screen they all look the same. LEN gives you the truth column that lets you sort the dirty from the clean.
Clean cell
"Emma Thompson"
13
Expected length. Nothing hidden.
Looks identical, secretly dirty
" Emma Thompson "
16
3 extra characters that will break every VLOOKUP.
The workflow: add a helper column with =LEN(A2). Sort by that column. Rows with unexpected lengths jump to the top — that's your cleanup list. Then run TRIM (or the full TRIM(SUBSTITUTE(A2, CHAR(160), " "))) and re-check with LEN to confirm the count matches expectation.

Quick Answer

LEN returns the number of characters in a text string — including letters, digits, punctuation, spaces, and every invisible character. It doesn't care what the characters are, only how many there are.

=LEN(text)

Example: =LEN("Hello World") returns 11 (5 + 1 space + 5). =LEN(A2) returns the character count of whatever's in cell A2.

📊 Text Cleanup Trio Practice Workbook

All 5 LEN examples plus TRIM and SUBSTITUTE patterns on 20 rows of realistic messy CRM data.

↓ Download .xlsx (Free)
Filetext-cleanup-trio-2026.xlsx
Size~22 KB
Sheets6 tabs
CoversTRIM · LEN · SUBSTITUTE
1985
Introduced
1
Argument
100%
Compat
50+
Templates Use It

Syntax

LEN takes exactly one argument — the text whose length you want to measure.

ArgumentTypeDescription
text Required The text string, a cell reference, or a formula returning text. Numbers get converted to text first (so LEN(1234) = 4). Empty cells return 0.

What LEN counts: every character including letters, digits, punctuation, spaces (CHAR 32), non-breaking spaces (CHAR 160), tabs, line breaks, and other non-printing characters. What it ignores: nothing — that's the point. LEN is the honest counter.

5 Worked Examples

Example 01

Basic — count characters in a string

Start with the simple case: how many characters are in "Hello World"?

=LEN("Hello World")

Result: 11 — that's 5 letters + 1 space + 5 letters. Every character counts.

Example 02

LEN counts spaces too (this is the key insight)

The whole reason LEN is useful for cleanup detection: it counts every space, including ones you can't see.

CellTextFormulaResult
A2"Emma"=LEN(A2)4
A3" Emma "=LEN(A3)8
A4"Emma "=LEN(A4)5

Same visible word. Different actual lengths. This is why LEN is a data-quality tool, not just a text-metrics tool.

Example 03

Before-and-after TRIM diff — invisible-junk counter

The killer LEN pattern. Subtract to see exactly how many phantom characters each row contains. Great for a data-quality dashboard column.

=LEN(A2) - LEN(TRIM(A2))

Returns the exact number of characters TRIM will remove. 0 means the row is clean. Anything else means there's phantom whitespace. Sort your table by this column and every dirty row surfaces to the top.

Raw NameLEN(raw)LEN(trimmed)Removed
"Emma Thompson"13130
" Emma Thompson "17134
"David Kim"1192
Example 04

Validate against a field-length limit

Combine LEN with IF to flag values outside allowed bounds. Perfect for pre-flight checks before pushing data to a system with strict field lengths.

=IF(LEN(A2)>60, "TOO LONG", "OK")

Common use cases: SMS max (160), tweet max (280), email subject line best-practice (<60), meta description SEO (<155), SKU codes (<20). The full reference table is below.

Example 05

Count occurrences of a character (the LEN + SUBSTITUTE trick)

Excel doesn't have a "count occurrences" function for characters, but LEN gives you one for free. The pattern: subtract the length after removing the character from the length before.

=LEN(A2) - LEN(SUBSTITUTE(A2, "-", ""))

Returns the count of dashes in A2. Change "-" to any character to count spaces (word count minus one), commas (CSV field count minus one), or "@" (email validation).

StringFormula targetCount
"emma@example.com"Count "@"1
"John, Jane, Bob, Alice"Count ","3
"The quick brown fox"Count " "3

Interactive Playground

Inputs
A2 → "Hello World" 11
A3 → "" (empty) → 0
A4 → " " (one space) → 1
A5 → 1234 (number) → 4
A6 → "emoji 😀" 8*

*Emoji counts as 2 code units in Excel

The Killer Pattern
=LEN(A2) - LEN(TRIM(A2))

Returns the count of characters TRIM would strip. Sort by this to find every dirty row instantly.

=LEN(A2) - LEN(SUBSTITUTE(A2, ",", ""))

Returns the count of commas in A2. Change "," to any character to count anything.

The Text Cleanup Trio

Three functions that work together to turn messy imports into production-clean data.

Character Limits Reference — For LEN Validation

The real-world field limits that make LEN worth using. Bookmark this table.

ContextFieldLimitValidation Formula
ExcelCell content maximum32,767=IF(LEN(A2)>32767,"OVER","OK")
ExcelFormula max length8,192=IF(LEN(A2)>8192,"OVER","OK")
ExcelSheet name max31=IF(LEN(A2)>31,"OVER","OK")
ExcelHeader/footer max255=IF(LEN(A2)>255,"OVER","OK")
SEOMeta title (best practice)60=IF(LEN(A2)>60,"TRUNC","OK")
SEOMeta description155=IF(LEN(A2)>155,"TRUNC","OK")
SEOURL slug (best practice)75=IF(LEN(A2)>75,"LONG","OK")
EmailSubject line (best practice)50=IF(LEN(A2)>50,"TRUNC","OK")
BusinessUS phone (digits only)10=IF(LEN(A2)=10,"OK","REVIEW")
BusinessUS ZIP code5=IF(LEN(A2)=5,"OK","REVIEW")

LEN vs LENB — Only Matters for CJK Languages

LEN counts characters. LENB counts bytes. For English, French, German, and any Latin-alphabet text, both return the same number — 1 character = 1 byte. For Chinese, Japanese, or Korean (CJK), most characters take 2 bytes, so LENB returns roughly double LEN.

=LEN("Hello") → 5
=LENB("Hello") → 5 (English: 1 char = 1 byte, both agree)

=LEN("你好") → 2
=LENB("你好") → 4 (Chinese: each char = 2 bytes)

Use LENB only when you're validating against a byte-based limit (some legacy systems, older databases, or fixed-width file formats). For character-based validation — which is what 99% of Excel users need — always LEN.

Common Errors

SymptomCauseFix
Returns 0 The cell is empty. Or the cell contains a formula that returns "" (empty string). This is correct behavior. If you need to distinguish "empty" from "zero-length string", use ISBLANK: =IF(ISBLANK(A2), "empty", LEN(A2)).
Returns unexpected large number Cell has phantom characters — trailing spaces, CHAR(160), line breaks — that inflate the count. That's LEN telling you the truth. Follow up with =LEN(A2) - LEN(TRIM(A2)) to see how many are phantom whitespace.
#VALUE! The argument is an error value (e.g. =LEN(#N/A)). Wrap with IFERROR: =IFERROR(LEN(A2), 0).
Emoji count seems wrong Excel counts emoji using UTF-16 code units. Most emoji are 2 code units (surrogate pair), some are 4+ if they include skin-tone modifiers. Expected behavior. If you're validating against a text-visible character limit, LEN over-counts emoji. For social media character limits, test with actual platform previews rather than relying on LEN alone.
Number formatted with commas returns wrong length LEN sees the underlying value, not the displayed format. =LEN(1234567) returns 7, not 9 (with commas). Convert the display format to text first: =LEN(TEXT(A2, "#,##0")) gives the length as-displayed.

📊 Practice on Real Messy Data

Every LEN validation pattern, the phantom-character diff column, and the count-occurrences trick — all on 20 realistic CRM rows.

↓ Get Workbook

Related Functions

Compatibility

PlatformSupportedVersionNotes
Excel for Windows1.0+ (1985)All versions
Excel for Mac1.0+All versions
Microsoft 365CurrentFull support
Excel OnlineCurrentFull support
Excel Mobile (iOS/Android)CurrentFull support
Google SheetsAllIdentical behavior
LibreOffice CalcAllIdentical behavior

How to Use LEN — Step by Step

  1. Click an empty cell next to the text you want to measure. If your data is in column A, use column B for the LEN helper.
  2. Type =LEN( — Excel auto-suggests as soon as you type "LE".
  3. Click the target cell (e.g. A2) or type the reference. Close with ) and press Enter.
  4. Fill down the whole column. Grab the fill handle (bottom-right corner) and drag, or double-click to auto-fill to match column A's height.
  5. For invisible-junk detection, add a diff column: =LEN(A2) - LEN(TRIM(A2)). Sort by this column descending — every dirty row rises to the top for cleanup.
  6. For validation, wrap in IF: =IF(LEN(A2) > 60, "TOO LONG", "OK"). Filter by the flag column to find every row that needs shortening before publishing.

Explore More Functions

📊 One More Time — Grab the Workbook

Every LEN pattern, plus TRIM and SUBSTITUTE. Free, one file, six sheets.

↓ Download Free

Frequently Asked Questions

Does LEN count spaces?

Yes — LEN counts every character including spaces, and that's the whole point of its usefulness for data quality. A leading space, trailing space, or double-space between words all count as characters.

This is why the =LEN(A2) - LEN(TRIM(A2)) pattern is so powerful: any non-zero result tells you exactly how much invisible whitespace TRIM will need to remove.

Why does LEN return a different number than I expect?

Almost always because the cell contains invisible characters. The most common culprits: trailing spaces (from copy-paste), CHAR(160) non-breaking spaces (from Word or web paste), and line breaks embedded in the cell.

Diagnostic sequence: (1) =LEN(A2) gives you the true count. (2) =LEN(TRIM(A2)) shows the count after stripping regular spaces. (3) If those two differ, TRIM will fix it. (4) If they're the same but the count is still too high, you probably have CHAR(160) — use =LEN(SUBSTITUTE(A2, CHAR(160), "")) to test.

How do I count words instead of characters?

Use the LEN + SUBSTITUTE trick: =LEN(TRIM(A2)) - LEN(SUBSTITUTE(TRIM(A2), " ", "")) + 1. TRIM first (so leading/trailing spaces don't inflate the count), then compare length before and after removing all spaces. Add 1 because N words have N-1 spaces between them.

Edge case: for an empty cell this returns 1, so wrap with IF: =IF(LEN(TRIM(A2))=0, 0, LEN(TRIM(A2)) - LEN(SUBSTITUTE(TRIM(A2), " ", "")) + 1).

Can LEN measure the length of a number?

Yes — Excel converts the number to text before counting. =LEN(1234) returns 4. =LEN(1234.5) returns 6 (four digits + decimal + one digit).

Watch out: LEN sees the underlying value, not the displayed format. A cell formatted with thousands separators like "1,234,567" still returns LEN = 7 (just the digits). To measure the displayed version, use =LEN(TEXT(A2, "#,##0")), which returns 9 for that same value.

What's the difference between LEN and LENB?

LEN counts characters. LENB counts bytes. For English and any Latin-alphabet language, they're identical because each character is 1 byte. For Chinese, Japanese, Korean (CJK), and some symbol sets, characters take 2 bytes, so LENB returns roughly double.

Use LENB only when validating against byte-based limits (some databases, legacy systems, fixed-width files). For everything else — social media limits, SEO fields, general validation — use LEN.

How does LEN handle empty cells?

Returns 0. An empty cell has zero characters — LEN reports that accurately.

Note: a cell containing a formula that returns "" (empty string) also gives LEN = 0. If you need to distinguish "truly empty" from "empty string result", use ISBLANK: =IF(ISBLANK(A2), "no data", LEN(A2)).

Can I use LEN with an entire range?

Not directly — LEN takes a single argument. But in Excel 365 / 2021 you can use it as a dynamic-array formula: =LEN(A2:A100) in a single cell spills the lengths across 99 rows.

To get a total character count across a range: =SUMPRODUCT(LEN(A2:A100)). Works in all Excel versions.

Does LEN work on cells with line breaks?

Yes, and each line break (CHAR 10 on Windows/Mac Excel, sometimes CHAR 13 in imports) counts as one character. So a two-line cell "Hello\nWorld" returns LEN = 11 (5 + 1 line break + 5), same as if it were one line with a space.

To count line breaks specifically: =LEN(A2) - LEN(SUBSTITUTE(A2, CHAR(10), "")).

Why does an emoji return more than 1 for LEN?

Excel uses UTF-16 encoding internally. Most emoji require two UTF-16 code units (called a surrogate pair), so LEN counts them as 2. Emoji with skin-tone or gender modifiers can count as 4 or more.

There's no simple workaround — this is how Excel represents Unicode. If you're validating a text field for a platform (like Twitter) that counts emoji as 1 or 2 characters depending on the emoji, LEN will over-count. Test against the actual platform preview rather than relying purely on LEN.

Can LEN be used in Data Validation?

Yes — this is one of its best uses. Under Data → Data Validation, choose "Custom" and enter a formula like =LEN(A2)<=60. Excel will reject any input that exceeds 60 characters at the point of entry.

Combine with an Input Message ("Max 60 characters") and Error Alert for a friendly user experience. Great for meta-description columns, SKU codes, or any field with a hard length ceiling.

How do I count characters excluding spaces?

Use the LEN + SUBSTITUTE trick in reverse: =LEN(SUBSTITUTE(A2, " ", "")). This removes every space, then LEN counts what remains.

Useful for word-processor-style character counts, or for validating fields where only non-space characters count against the limit (some legacy database columns work this way).

Is there a maximum value LEN can return?

LEN can return up to 32,767 — the maximum number of characters a single Excel cell can hold. If somehow you pass a longer string via formula concatenation, the input itself will already be truncated to 32,767 by the cell.

For formulas (versus cells), the string limit is much lower — ~8,192 characters in the formula itself. LEN of a very long formula-generated string is fine as long as the intermediate value stays under the cell limit.

Turn LEN Patterns Into One-Click Validation

Excel Wizard writes LEN validation formulas — for meta tags, tweets, SKU codes, phone digits — from a plain-English prompt. Detects invisible junk, sets up length-limit flags, and builds character-count dashboards, right inside Excel.

Get Excel Wizard Add-in →