Skip to content

Lesson 87 of 92 · Free Excel Course

Excel · Excel function reference

Excel LEN Function: Syntax, Examples and Common Errors

How the Excel LEN function counts characters, spaces included. Count words, check character limits, find hidden spaces. Free practice workbook.

The LEN function counts how many characters are in a piece of text and returns that count as a number. Letters, digits, punctuation and spaces all count, including the invisible spaces at the end of a cell. That makes LEN useful far beyond "how long is this?": it checks character limits, counts words, and catches hidden spaces that break lookups. LEN works in Excel for Microsoft 365 (Windows and Mac), Excel for the web, and Excel 2024, 2021, 2019 and 2016.

Syntax

=LEN(text)
  • text (required): the text whose length you want. It can be a cell reference such as A2, text typed in quotes such as "Phoenix, AZ", or another formula such as TRIM(A2). Spaces count as characters. An empty cell gives 0.

That's the only argument. If you give LEN a number, it counts the digits of the stored value (more on that in the examples). LEN looks at one value at a time; to count a whole range, put it inside SUMPRODUCT, as in =SUMPRODUCT(LEN(A2:A100)).

Examples

1. Microsoft's example. This is the example from Microsoft's LEN page, with the same three strings. The third one has five spaces before "One" and three after it.

B4=LEN(A4)
AB
1DataLength
2Phoenix, AZ11
30
4 One 11
B2 is =LEN(A2) and B3 is =LEN(A3). The comma and space in Phoenix, AZ count, the empty cell gives 0, and A4 is 3 letters plus 8 spaces.

2. Check a character limit. Online stores, ad platforms and forms often cap a field at a set number of characters. Say your product titles must be 40 characters or fewer. =LEN(A2) gives the length, and an IF turns it into a message that also says how far over you are.

C3=IF(LEN(A3)>40,"Too long by "&LEN(A3)-40,"OK")
ABC
1Product titleCharactersStatus
2Stainless steel water bottle, 32 oz35OK
3Insulated stainless steel water bottle with straw lid53Too long by 13
4Bamboo cutting board20OK
53 minus 40 is 13. The red fill comes from a conditional formatting rule that uses LEN too.

To color the long titles automatically:

  1. Select the titles, for example A2:A4.
  2. Go to Home > Conditional Formatting > New Rule and choose Use a formula to determine which cells to format.
  3. Type =LEN($A2)>40, click Format, pick a fill and click OK twice.

To stop people typing a long title in the first place, use Data > Data Validation, set Allow to Text length, Data to less than or equal to and Maximum to 40. Excel then rejects anything longer. Both features are covered in conditional formatting and data validation.

3. Count words and characters. LEN can't see words, but it can count spaces: take the length with spaces, subtract the length without them (SUBSTITUTE swaps every " " for nothing), and add 1. The same trick counts any character, such as the commas in a tag list.

B2=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1
ABC
1TextCountWhat it counts
2 The quick brown fox 4Words
3red,blue,green,gold3Commas
4red,blue,green,gold4Tags (commas + 1)
TRIM first turns the messy sentence into "The quick brown fox" (19 characters, 16 without spaces): 19 - 16 + 1 = 4. B3 is =LEN(A3)-LEN(SUBSTITUTE(A3,",","")).

Without TRIM, the extra spaces would be counted as extra words. SUBSTITUTE is case-sensitive, so to count a letter in either case, compare against an upper-case copy: =LEN(A2)-LEN(SUBSTITUTE(UPPER(A2),"E","")).

4. Numbers and dates. LEN counts the value Excel stores, not what the number format shows. This trips people up more than anything else about LEN.

B5=LEN(TEXT(A5,"0.00"))
ABC
1Cell showsLENWhy
21.503Stored as 1.5
3$1,250.004Stored as 1250
411/22/20265Stored as 46348
51.504TEXT counts what you see
B2:B4 use =LEN(A2) and so on. Dates are serial numbers, so every date this century gives 5. TEXT turns the number into the text you see first.

So never use LEN to check how many decimals a number "has" on screen; the format can add zeros LEN never sees.

5. Find hidden spaces. A product code that should be 6 characters but returns 7 almost always has a stray space. Put =LEN(A2) next to the codes, or flag the bad ones with =LEN(A2)<>LEN(TRIM(A2)), which shows TRUE wherever extra spaces are hiding. This is the quickest way to find out why a VLOOKUP or a COUNTIF can't match text that looks identical.

C3=LEN(A3)<>LEN(TRIM(A3))
ABC
1CodeLENExtra spaces?
2AB12346FALSE
3AB1234 7TRUE
4CD56786FALSE
A3 has a space after the 4. It looks the same as the others until LEN counts it.

Common errors

  • The count is higher than you expect. Hidden characters: spaces at the ends, a non-breaking space from a web page (character 160) or a line break inside the cell (Alt+Enter; on a Mac, Option+Return or Control+Option+Return). TRIM removes extra normal spaces, SUBSTITUTE(A2,CHAR(160)," ") swaps non-breaking ones (on a Mac, where CHAR uses the Mac character set, use UNICHAR(160)), and CLEAN removes line breaks and other non-printing characters.
  • A number or date gives a "wrong" count. LEN ignores formatting (example 4). Wrap the value in TEXT with the format you want counted.
  • An empty cell counts as 1 word. The word formula always adds 1. Use =IF(LEN(TRIM(A2))=0,0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1).
  • LEN returns an error such as #N/A. If the cell it reads holds an error, LEN passes that error on. Fix the source formula, or wrap it: =IFERROR(LEN(A2),0).
  • #NAME? The function name is misspelled (for example =LENGTH(A2)). Excel's function is LEN.
  • An emoji counts as 2. Some emoji are stored as two code units. Microsoft says that in workbooks set to Compatibility Version 2, LEN counts these "surrogate pairs" as one character, while variation selectors still count separately.

To check whether a cell is empty rather than how long it is, =LEN(A2)=0 is a handy test that also treats a formula returning "" as empty; ISBLANK and logic checks explains the difference.

Related functions

Try it yourself

Download the practice workbook. The Practice sheet has Microsoft's example, two product titles to check against a 40-character limit, a messy sentence to count words in, a tag list, a formatted number and a code with a hidden space. Fill in the yellow cells and compare with the Answers sheet.

Frequently asked questions

Does LEN count spaces in Excel?

Yes. Every space counts as one character, including spaces at the start and end of the text that you can't see. =LEN(" One ") gives 11, not 3. To leave out the extra spaces, count the trimmed text instead: =LEN(TRIM(A2)).

How do I count words in a cell with LEN?

Count the spaces and add one: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1. TRIM first cuts double spaces down to one, so the count stays right. Wrap it as =IF(LEN(TRIM(A2))=0,0,...) if some cells are empty, or an empty cell counts as 1 word.

Why does LEN give the wrong count for a number or a date?

LEN counts the value stored in the cell, not what the number format shows. A cell showing 1.50 holds 1.5, so LEN gives 3. A date like 11/22/2026 is stored as the serial number 46348, so LEN gives 5. To count what you see, wrap the value in TEXT: =LEN(TEXT(A2,"0.00")).

How do I count the characters in a whole column?

Use =SUMPRODUCT(LEN(A2:A100)). SUMPRODUCT runs LEN on every cell in the range and adds the results. In Excel for Microsoft 365 and Excel 2021 or later you can also type =SUM(LEN(A2:A100)).

What is the difference between LEN and LENB?

LEN counts characters. LENB counts bytes, which only gave a different answer in languages that use double-byte characters, such as Japanese, Chinese and Korean. Microsoft now lists LENB as deprecated, so use LEN.