Excel LEN and LENB: count characters and understand byte counts

Use LEN to count characters in Excel, including spaces. Microsoft has deprecated LENB, which uses a legacy byte-counting rule. To check a UTF-8 size limit, count the bytes of the actual UTF-8 encoding.

Count characters and spaces with LEN

Type AB CD in A2 and 가나다라 in A3. Put the first two formulas below in C2 and C3. They return 5 and 4. The first string contains four letters and a space. The last formula uses an empty string and returns 0.

=LEN(A2)
=LEN(A3)
=LEN("")

Microsoft’s LEN function reference

Why LENB can return different lengths

Try both formulas on the same cells. Under the legacy Office rule, a default language that supports a double-byte character set, such as Korean, counts these Hangul characters as two each. The results can be 5 and 8. A default language without that support counts each character as one and can give 5 and 4.

=LENB(A2)
=LENB(A3)

Microsoft’s legacy Office rule for LENB

Compare with the actual UTF-8 size

AB CD takes 5 bytes in UTF-8. 가나다라 takes 12 because each of these four Hangul syllables uses 3 bytes. A CSV file can also contain delimiters and line breaks. For an upload limit, measure the saved file or the actual data being sent.

When matching-looking text has different lengths

The formulas below return 2 and 3 because the second string has a trailing space. For the same reason, check pasted cells for line breaks or other invisible characters.

=LEN("AB")
=LEN("AB ")

An emoji can consist of several Unicode elements. In a Compatibility Version 2 workbook, LEN counts a surrogate pair as one character. A variation selector that changes an emoji’s appearance can still be counted separately, so the result can differ from the number of symbols you see.