Dev Basics · 5 min read
Character Encoding: ASCII, Unicode, and UTF-8
If you have ever seen a name render as strange symbols, you have met a character-encoding problem. Understanding the difference between a character set and an encoding makes these bugs make sense.
This guide untangles ASCII, Unicode, and UTF-8.
Try it yourself with the related tool.
Look up characters →Advertisement
ASCII: the original set
ASCII is a 7-bit character set covering the first 128 characters — English letters, digits, punctuation, and control characters. It was enough for early English-language computing but cannot represent accents, other scripts, or emoji.
Unicode: a number for every character
Unicode assigns a unique number, called a code point, to every character in every writing system — over a hundred thousand of them. A code point is written like U+00E9 for é. Unicode is the map from characters to numbers; it does not say how those numbers are stored as bytes.
UTF-8: how the numbers become bytes
UTF-8 is the dominant encoding of Unicode code points into bytes. ASCII characters take one byte, and others take two to four. That backward compatibility with ASCII plus its efficiency is why UTF-8 powers the modern web.
Why text gets garbled
Mojibake — text turning into odd symbols — happens when bytes encoded one way are read as another. A multi-byte UTF-8 character read as single-byte Latin-1 shows up as several wrong characters. The fix is to make sure the same encoding (usually UTF-8) is declared and used end to end.
