Skip to content

LEN

Returns the number of characters in a piece of text, spaces included.

Syntax

=LEN()

Text

All versions of Excel.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
SKU
Product
Length
2
FX-1010
Nitrile gloves
7
3
FX-1085
Floor cleaner
4
FX-2
Pallet wrap
5

C2 =LEN(A2) returns 7

How LEN works

LEN returns the number of characters in text. Spaces, punctuation and line breaks all count. It is a small function that earns its place in checks and in other text formulas.

What LEN counts

=LEN("Nitrile gloves") returns 14: 13 letters and one space. Every character counts, including spaces at the start and end, which you can't see in the cell. An empty cell returns 0.

LEN measures the stored value, not what the cell displays. A cell holding the number 1234.5 formatted as $1,234.50 has a LEN of 6, the length of 1234.5. A date such as 15-Mar-2025 is stored as the serial 45731, so LEN returns 5. If you want the length of the displayed text, measure it through TEXT: =LEN(TEXT(B2,"dd-mmm-yyyy")) returns 11.

Common uses

Validating a code. Many IDs have a fixed length. =IF(LEN(A2)=8,"OK","Check length") flags codes that are too short or too long, for instance because a leading zero was lost.

Spotting hidden spaces. If a lookup fails even though two cells look identical, compare the lengths. =LEN(A2)-LEN(TRIM(A2)) returns the number of extra spaces that TRIM would remove. Anything above 0 means the cell has leading, trailing or doubled spaces.

Counting a character. Remove the character with SUBSTITUTE and see how much shorter the text becomes: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) counts the commas in A2. For a word count, count the spaces and add one: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1. Use this one on text that isn't empty, because it returns 1 for an empty cell.

Working with LEFT, RIGHT and MID. LEN gives you the length that these functions need when you want to keep or drop a fixed number of characters at one end: =LEFT(A2,LEN(A2)-4) removes the last four characters, and =RIGHT(A2,LEN(A2)-FIND(".",A2)) takes everything after the first dot.

LEN is not the same as LENB

Excel also has LENB, which counts bytes for double-byte languages. It matches LEN unless a double-byte language is your default, so use LEN.

Text limits

A cell can hold at most 32,767 characters, and Excel displays only the first 1,024 of them in the cell itself. LEN measures the full length, which makes it useful to check whether imported text was cut off at a system's own limit, such as 255 characters.

Arrays

In Microsoft 365, LEN accepts a range and returns an array: =LEN(A2:A9) spills the length of each cell. Wrap it in SUM to total the characters, or in MAX to find the longest entry: =MAX(LEN(A2:A9)).

Arguments

text
The text to measure. Usually a cell such as A2. Numbers are measured as the text they would show in a General-format cell, and an empty cell has length 0.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Count the characters in a code

C2 =LEN(A2)

Result: 7

Seven characters: FX, a dash, and four digits.

C2
A
B
C
1
SKU
Product
Length
2
FX-1010
Nitrile gloves
7
3
FX-1085
Floor cleaner
4
FX-2
Pallet wrap
5

C2 =LEN(A2) returns 7

Example 2

Flag codes of the wrong length

C3 =IF(LEN(A3)=8,"OK","Check length")

Result: Check length

FIN-305 has 7 characters because a leading zero was lost. The same formula in C2 returns OK.

C3
A
B
C
1
Staff ID
Name
Check
2
ENG-0412
Priya
3
FIN-305
Marcus
Check length
4
OPS-1120
Elif
5

C3 =IF(LEN(A3)=8,"OK","Check length") returns Check length

Example 3

Count how many times a character appears

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

Result: 3

The text is 23 characters long and 20 without the commas, so there are 3 commas. That means 4 tags.

B2
A
B
C
1
Tags
Count
2
gloves,wrap,tape,labels
3
3
4

B2 =LEN(A2)-LEN(SUBSTITUTE(A2,",","")) returns 3

Example 4

Find hidden extra spaces

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

Result: 4

The cell has 17 characters. TRIM leaves "Anya Kowalski" with 13. The difference is two leading spaces, one extra space in the middle and one trailing space.

B2
A
B
C
1
Name
Extra spaces
2
Anya Kowalski
4
3
4

B2 =LEN(A2)-LEN(TRIM(A2)) returns 4

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, return the number of characters in the tags in A2.

Answer in B2.

B2
A
B
C
1
Tags
Length
Commas
2
gloves,wrap,tape
3
labels
4
bin,rack,shelf,tote,pallet
5
film,strap
6
7

Common mistakes

  • LEN counts spaces. A cell that looks like "Anya" may have a length of 5 because of a trailing space. Compare with LEN(TRIM(A2)) when a lookup or match fails for no visible reason.
  • LEN measures the stored value, not the display. A date such as 15-Mar-2025 has a LEN of 5, from the serial number 45731. Use LEN(TEXT(B2,"dd-mmm-yyyy")) to measure the display text.
  • A formatted number loses its format. $1,234.50 has a LEN of 6, not 9, because LEN sees 1234.5.
  • The word-count trick LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 returns 1 for an empty cell. Wrap it in an IF that returns 0 when LEN(TRIM(A2))=0.
  • Line breaks count as characters. A cell that shows two lines has a CHAR(10) between them, so LEN is one higher than the count of visible characters. CLEAN removes it.

Questions people ask

How do I count characters in a cell in Excel?

Use `=LEN(A2)`. It counts every character in the cell, including spaces and punctuation.

How do I count a specific character in a cell?

Subtract the length without that character from the full length: `=LEN(A2)-LEN(SUBSTITUTE(A2,",",""))`. Change the comma to the character you want. SUBSTITUTE is case-sensitive, so "a" and "A" are counted separately.

Why is LEN bigger than the text I can see?

The cell has hidden spaces, a line break or another non-printing character. Use TRIM to remove extra spaces and CLEAN to remove non-printing characters, and compare lengths to confirm.

Does LEN count spaces?

Yes. Every space counts, at the start, between words and at the end. TRIM removes the extra ones before you measure.

How do I find the longest text in a column?

In Microsoft 365, use `=MAX(LEN(A2:A20))`. In older versions, use `=MAX(INDEX(LEN(A2:A20),0))`, or enter the first formula with Ctrl+Shift+Enter.

Learn LEN in a real sheet.

LEN is taught in Logic and text, lesson 7: TRIM and CLEAN. Each lesson is a short, graded exercise like the one above.