Why String Length Lies: Characters, Code Points and Bytes
How long is a string? Graphemes, code points, UTF-16 units and UTF-8 bytes explained, plus SMS segments, limits and truncating without broken emoji.

Why String Length Lies: Characters, Code Points and Bytes
Ask four programs how long the family emoji 👨👩👧👦 is and you can get four answers: 1, 7, 11 and 25. None of them is wrong. They are counting different things, and the difference causes real bugs: names cut off in the middle of an accent, previews ending in a broken symbol, database errors for text that looked short enough, and text messages that cost three times what you expected. The free String Length and Safe Truncation tool counts every unit at once and truncates text safely.
Four ways to count
- Graphemes are what a reader perceives as one character. An e with an accent written as two code points, a flag made of two regional indicator letters, and a family emoji built from four people and three joiners are each one grapheme. The family emoji counts as 1.
- Code points are Unicode's numbered characters. Python's
len()and most database character counts use them. The family emoji is 7. - UTF-16 code units are what JavaScript, Java and C# report as a string's length. Characters beyond the first 65,536 code points, including most emoji, take two units each. The family emoji is 11.
- UTF-8 bytes are what files, network messages and many storage limits measure. ASCII takes one byte, most European accented letters two, Chinese and Japanese characters three and emoji four each. The family emoji is 25 bytes.
Where it matters
Byte limits hide in many places. The bcrypt password hash ignores everything after 72 bytes, so a long passphrase in a non-Latin script may be silently shortened. File names on most Linux and macOS file systems are limited to 255 bytes, not characters. DNS labels and email local parts have limits in bytes too.
Character limits are just as varied. MySQL VARCHAR(255) counts characters, but with the utf8mb4 character set each can take four bytes, which matters for index size limits. Social networks and search result titles count in their own ways, so the tool's limits table is a guide rather than an official reference.
Text messages
SMS has its own rules. If every character belongs to the GSM-7 alphabet, one message holds 160 characters, and longer messages are split into parts of 153 because each part needs a header. Some symbols, including the euro sign, square brackets and curly braces, count as two. A single character outside GSM-7, such as an emoji, a curly apostrophe pasted from a word processor or many accented letters, switches the whole message to UCS-2, where one part holds only 70 characters, or 67 when split. A 150-character notification with one emoji costs three messages instead of one.
Truncating without breaking characters
Cutting a string at a fixed number of UTF-16 units or bytes can land in the middle of a character. The result shows a replacement symbol, a lone skin-tone patch or half a flag. Safe truncation works grapheme by grapheme: it adds whole characters until the next one would exceed the limit, counting the ellipsis as part of the limit, and can back up to the last word boundary for a neater result.
The tool also lists each character with its code points and its size in UTF-8 and UTF-16, which is useful for debugging text that refuses to fit.
Step by step
- Paste the text.
- Read the counts for characters, code points, UTF-16 and bytes.
- Check the limits table and SMS segment count.
- Choose a truncation limit and the unit it is measured in.
- Add an ellipsis or word boundary if you want, then copy the result.
Privacy
Counting happens in your browser and the text is not sent anywhere.



