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.
The Character-Count Detective
Two strings that look identical on-screen. LEN reveals which one is silently broken.
=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.
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.
Syntax
LEN takes exactly one argument — the text whose length you want to measure.
| Argument | Type | Description |
|---|---|---|
| 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
Basic — count characters in a string
Start with the simple case: how many characters are in "Hello World"?
Result: 11 — that's 5 letters + 1 space + 5 letters. Every character counts.
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.
| Cell | Text | Formula | Result |
|---|---|---|---|
| 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.
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.
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 Name | LEN(raw) | LEN(trimmed) | Removed |
|---|---|---|---|
| "Emma Thompson" | 13 | 13 | 0 |
| " Emma Thompson " | 17 | 13 | 4 |
| "David Kim" | 11 | 9 | 2 |
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.
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.
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.
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).
| String | Formula target | Count |
|---|---|---|
| "emma@example.com" | Count "@" | 1 |
| "John, Jane, Bob, Alice" | Count "," | 3 |
| "The quick brown fox" | Count " " | 3 |
Interactive Playground
Inputs
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
Returns the count of characters TRIM would strip. Sort by this to find every dirty row instantly.
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.
| Context | Field | Limit | Validation Formula |
|---|---|---|---|
| Excel | Cell content maximum | 32,767 | =IF(LEN(A2)>32767,"OVER","OK") |
| Excel | Formula max length | 8,192 | =IF(LEN(A2)>8192,"OVER","OK") |
| Excel | Sheet name max | 31 | =IF(LEN(A2)>31,"OVER","OK") |
| Excel | Header/footer max | 255 | =IF(LEN(A2)>255,"OVER","OK") |
| Twitter/X | Post character limit | 280 | =IF(LEN(A2)>280,"OVER","OK") |
| Post text limit | 3,000 | =IF(LEN(A2)>3000,"OVER","OK") | |
| Caption limit | 2,200 | =IF(LEN(A2)>2200,"OVER","OK") | |
| SMS | Single segment (Latin) | 160 | =IF(LEN(A2)>160,"MULTI","1 SEG") |
| SEO | Meta title (best practice) | 60 | =IF(LEN(A2)>60,"TRUNC","OK") |
| SEO | Meta description | 155 | =IF(LEN(A2)>155,"TRUNC","OK") |
| SEO | URL slug (best practice) | 75 | =IF(LEN(A2)>75,"LONG","OK") |
| Subject line (best practice) | 50 | =IF(LEN(A2)>50,"TRUNC","OK") | |
| Business | US phone (digits only) | 10 | =IF(LEN(A2)=10,"OK","REVIEW") |
| Business | US ZIP code | 5 | =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.
=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
| Symptom | Cause | Fix |
|---|---|---|
| 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.
Related Functions
Compatibility
| Platform | Supported | Version | Notes |
|---|---|---|---|
| Excel for Windows | ✓ | 1.0+ (1985) | All versions |
| Excel for Mac | ✓ | 1.0+ | All versions |
| Microsoft 365 | ✓ | Current | Full support |
| Excel Online | ✓ | Current | Full support |
| Excel Mobile (iOS/Android) | ✓ | Current | Full support |
| Google Sheets | ✓ | All | Identical behavior |
| LibreOffice Calc | ✓ | All | Identical behavior |
How to Use LEN — Step by Step
- 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.
- Type
=LEN(— Excel auto-suggests as soon as you type "LE". - Click the target cell (e.g. A2) or type the reference. Close with
)and press Enter. - 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.
- 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. - 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.
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.
Templates That Use LEN
Data Quality Dashboard
Phantom-character counts per column, per row. LEN diff against TRIM makes junk visible before it breaks production.
USES LENSEO Title & Meta Planner
LEN validates every title stays under 60 chars, every meta description under 155. Instant OK/TRUNC flag column.
USES LENSocial Media Scheduler
Pre-flight character checks for Twitter (280), LinkedIn (3000), Instagram (2200). No more "post too long" surprises.
USES LENSMS Campaign Planner
Segment counter using LEN — 160-char single-segment, then 153 per segment for multi. Direct impact on send cost.
USES LENProduct Catalog
SKU length, description length, meta-title length — every field validated before feed export.
USES LENEmail Marketing Tracker
Subject-line length validation (50 char best-practice), preview text (90-140 chars). LEN is the whole optimization loop.
USES LENCustomer Database
Phone-digit-count validation (must equal 10), ZIP-code validation (must equal 5), plus phantom-space detection column.
USES LENContent Calendar
Post-length previews for every planned piece — headline, excerpt, teaser. LEN flags anything that'll get cut.
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 →