ShareYourGroupShareYourGroupExcel Formulas

Text functions

LEN function in Excel

LEN returns the number of characters in a text, counting spaces.

LEN counts characters. That sounds like a curiosity, but it is one of the most useful tools for checking data: finding hidden spaces, validating the length of a code or phone number, and working out where to cut a text.

Syntax

=LEN(text)
ArgumentWhat it is
textThe text, or a cell that holds it.

Examples

Each result below is what Excel itself showed for the formula on the sample sheet.

Sample sheet: Text as people really type it: stray spaces, mixed capitals, codes with dashes.
ABCD
1Full nameEmailCodeAmount as text
2  asha   verma asha.verma@example.comPB-10-12341,250
3RAVI KUMARravi@example.orgDL-08-0042300
4meena gillmeena.gill@example.comMH-12-9876 45.50 
5Kabir Khankabir@example.netRJ-14-000712 kg

How it works

LEN returns how many characters a cell contains. Letters, digits, punctuation and spaces all count, including spaces at the start and end that you cannot see.

For a number, LEN counts the characters of the stored value, not of the display. A cell that holds 1250 and shows "1,250.00" has a length of 4.

Finding invisible spaces

Two cells can look identical and fail to match in a lookup because one has a space at the end. Put =LEN(A2) beside them. If one says 10 and the other 11, you have found the reason. The second and third examples show the extra count, and TRIM removes it.

Checking lengths

Many identifiers have a fixed length: a ten-digit mobile number, a six-digit PIN code, a ten-character PAN. A helper column with =LEN(A2) and a filter for anything that is not the right number finds the bad entries quickly. As a Data Validation rule, =LEN(A2)=10 stops wrong lengths from being typed at all.

Remember that a number format can hide the truth. A mobile number stored as a number loses any leading zero, so its length may be right only by luck.

Counting a character or a word

There is no function that counts how often a character appears in a cell. The standard trick uses LEN twice:

=LEN(text) - LEN(SUBSTITUTE(text, character, ""))

Remove every copy of the character, and the text gets shorter by exactly the number of copies. The sixth example counts dots.

The same idea counts words: count the spaces and add one. Trim the text first, or double spaces will inflate the figure: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1.

To count a longer piece of text, divide by its length: =(LEN(A1)-LEN(SUBSTITUTE(A1,"ab","")))/LEN("ab").

Helping LEFT, RIGHT and MID

LEN supplies the total that the cutting functions need.

Adding up lengths

=SUMPRODUCT(LEN(A2:A100)) gives the total number of characters in a range, useful when text has a size limit.

Common mistakes

In Google Sheets

LEN is the same in Google Sheets.

Related functions

Every result on this page was calculated in Microsoft Excel (version 16.0, build 20326) on 12 November 2026, not typed by hand.

This is an independent help site. It is not connected with or approved by Microsoft. Excel and Microsoft 365 are trademarks of Microsoft Corporation, named here only to say which program a formula is for. The people and figures in the sample sheets are made up.