ASCII vs. Unicode vs. UTF-8
ASCII is an old table with only 128 characters (unaccented letters, digits, basic symbols). Unicode is a much broader standard that assigns a unique number (code point, e.g. U+00E9) to virtually every character in every language, including emoji. UTF-8 is the most common way to store those Unicode code points as bytes — ASCII characters take 1 byte, accented and special characters can take 2 to 4 bytes.
What it's for
Useful for debugging text encoding issues, understanding why a character shows up "broken" (mojibake) in a system, or checking the real byte size of a string.
How many bytes each character takes
- A: U+0041, decimal 65, 1 byte (41).
- ü: U+00FC, 2 bytes (C3 BC).
- €: U+20AC, 3 bytes (E2 82 AC).
- 😀: U+1F600, 4 bytes (F0 9F 98 80).
Counting traps
In JavaScript a string's length counts UTF-16 units, so a single emoji reports 2. Another trap is that one visible "ü" can be a single code point (U+00FC) or "u" followed by a combining diaeresis (U+0075 U+0308). They look identical on screen yet compare as different strings, which is why normalization to NFC or NFD matters before comparing or hashing text.
The byte count matters for limits such as a database column declared in bytes: "€" is one character on screen but three bytes in UTF-8, so compare lengths in the same unit.
Frequently asked questions
Why do accented characters sometimes turn into garbage?
Usually because text saved as UTF-8 is being read as if it were another encoding (like ISO-8859-1), making UTF-8's multi-byte sequences get misinterpreted.
Is every ASCII character also valid UTF-8?
Yes — the first 128 UTF-8 characters are identical to ASCII, each taking 1 byte.