Why text has several “lengths”
Computers store text as numbers, and there is more than one way to do it. The same string can have different sizes depending on the encoding:
| Measure | Used by | “é” | “你” | “🚀” |
|---|---|---|---|---|
| UTF-8 bytes | the web, files, most databases and APIs | 2 | 3 | 4 |
| UTF-16 units | JavaScript .length, Java, Windows, many form limits |
1 | 1 | 2 |
| Code points | Python len(), Unicode itself |
1 | 1 | 1 |
| Grapheme clusters | what a reader sees as one character | 1 | 1 | 1 |
So a 255-character database column defined in bytes might hold only 63 emoji, and a form that counts UTF-16 units will think “🚀” is two characters.
When to check
- Database and API limits: VARCHAR lengths in MySQL count characters but row-size limits count bytes; many APIs cap payloads in bytes.
- SMS: messages are encoded in GSM-7 or UCS-2; see the Social Media Character Counter for segment counts.
- Filenames and URLs: many systems limit these in bytes.
The per-character table shows the code points and UTF-8 bytes of each visible character, which makes it easy to find the one invisible or unexpected symbol inflating a size.
Worked example
Here is what the Text Size & Byte Counter returns for its built-in example. Click Try an example in the tool above to load it, then change it as you like.
Hello, wörld! 你好 🚀| Result | Value |
|---|---|
| UTF-8 | 26 B |
| UTF-16 | 38 B |
| Characters | 18 |
| Code points | 18 |
| UTF-16 units (.length) | 19 |
| UTF-32 | 72 B |
Questions
How many bytes is one character?
In UTF-8, 1 byte for basic Latin letters and digits, 2 for most accented letters and Greek, Cyrillic, Hebrew and Arabic, 3 for most Chinese, Japanese and Korean characters, and 4 for emoji and rarer symbols.
Why does JavaScript say my emoji has length 2?
JavaScript strings use UTF-16, and characters outside the Basic Multilingual Plane, such as most emoji, are stored as two 16-bit units (a surrogate pair).
Last reviewed · How Textkiln tools work