Understanding the string length and byte size calculator β concept and principle
The "length" of a text depends on what you count: characters, UTF-8 bytes, UTF-16 bytes, words or lines. A database column, a message field or an API limit usually measures only one of them, and the numbers differ sharply for Korean, Chinese or emoji. This calculator gives all five at once so you can check a value against the limit that actually applies.
How it is calculated
- Characters: the number of Unicode code points.
- UTF-8 bytes: each code point takes 1 byte (U+0000βU+007F), 2 bytes (up to U+07FF), 3 bytes (up to U+FFFF, including all Hangul syllables) or 4 bytes (above U+FFFF, such as most emoji).
- UTF-16 bytes: number of 16-bit code units Γ 2. Characters in the Basic Multilingual Plane use one unit; characters above U+FFFF use two (a surrogate pair).
- Words: the trimmed text split on runs of whitespace.
- Lines: the number of line-feed characters plus one.
The principle
Text is stored as numbers, and different encodings spend different amounts of space per number. UTF-8 was designed so that plain English stays one byte per letter, while scripts outside ASCII cost more. UTF-16 spends at least two bytes on everything, which makes it more compact than UTF-8 for East Asian text written mostly in 3-byte characters, but larger for ASCII. The word count only looks for spaces, so it reflects word-separated languages well.
Worked example
- Input: μλ νμΈμ Hello.
- Characters: 5 Hangul syllables + 1 space + 5 Latin letters = 11.
- UTF-8: 5 Γ 3 + 1 + 5 Γ 1 = 15 + 1 + 5 = 21 bytes.
- UTF-16: all 11 characters are in the BMP, so 11 units Γ 2 = 22 bytes.
- Words: one space separates two groups, so 2 words; there is no line break, so 1 line.
How to read the result
Compare each count with how the target system measures length. Many SQL databases define VARCHAR in characters, but some (or some settings) count bytes, and indexes often have byte limits. JavaScript's .length and Java's String.length() return UTF-16 units, while Python's len() returns code points. Plain GSM SMS allows 160 characters of its 7-bit alphabet; any character outside it switches the message to UCS-2, where the limit is 70.
Common mistakes
- Sizing a byte-limited field by character count: 100 Korean characters need 300 UTF-8 bytes.
- Forgetting that a trailing newline adds one more (empty) line to the count.
- Expecting the word count to work for Chinese or Japanese text, which is written without spaces.
Frequently asked questions
How many bytes is one Korean character?
3 bytes in UTF-8 and 2 bytes in UTF-16 for any precomposed Hangul syllable.
Why is UTF-16 bytes not always characters Γ 2?
Characters above U+FFFF, such as π, use two 16-bit units, so they take 4 bytes.
Is a BOM counted?
No, only the text itself is encoded.
Sources: The Unicode Consortium, The Unicode Standard, Chapter 3 (Unicode encoding forms) Β· IETF RFC 3629, UTF-8, a transformation format of ISO 10646 Β· 3GPP TS 23.038, Alphabets and language-specific information (GSM 7-bit alphabet)