How to Use the LENB Function in Google Sheets | Count the Byte Length of a String
How to Use the LENB Function
The LENB function counts the byte length of a specified text string. While the standard LEN function counts every character as 1 regardless of width, LENB counts half-width characters as 1 and full-width characters as 2.
Syntax
=LENB(string)
- string: The text string or cell reference whose byte length you want to find (required).
Example Using a Table
Here is an example comparing character count (LEN) and byte count (LENB) for the customer name data below.
| Row | Column A (Customer Name) | Column B (Characters: LEN) | Column C (Bytes: LENB) |
|---|---|---|---|
| 1 | Customer Name | Characters | Bytes |
| 2 | 田中太郎 | =LEN(A2) → 4 |
=LENB(A2) → 8 |
| 3 | Tanaka Taro | =LEN(A3) → 11 |
=LENB(A3) → 11 |
| 4 | ㈱サンプルABC | =LEN(A4) → 8 |
=LENB(A4) → 13 |
- Formula:
=LENB(A4) - Result:
13
㈱サンプルABC consists of 5 full-width characters (10 bytes) plus 3 half-width characters (3 bytes), totaling 13 bytes.
Common Errors and Notes
- Checking for Mixed Full-Width and Half-Width Input: If
LEN(A2)equalsLENB(A2), all characters are half-width; ifLENB(A2) = LEN(A2) * 2, all characters are full-width. This makes it useful for input format validation. - Half-Width Katakana Counts as 1 Byte: Half-width katakana characters (e.g.,
アイウ) are counted as 1 byte per character. - Differs from Actual UTF-8 File Size: In UTF-8 encoding, Japanese characters typically take 3–4 bytes, but
LENBis fixed to thehalf-width = 1, full-width = 2specification.
Frequently Asked Questions
Q. When is the LENB function used?
A. It is used when validating mixed full-width and half-width data against fixed-length file or legacy system import limits (such as a maximum of 15 full-width characters / 30 half-width bytes).
Q. How does LENB count 3-byte UTF-8 characters such as Japanese text?
A. Because Google Sheets' LENB function follows the legacy Shift-JIS (double-byte character set) standard, all full-width characters such as Japanese are counted as 2 bytes, while half-width alphanumeric characters and half-width katakana are counted as 1 byte.