Character Encoding: ASCII, Unicode & UTF-8 Explained
Every string your program handles is, underneath, a sequence of bytes — and the rules for turning characters into bytes are character encoding. Get them wrong and you get é where you wanted é. Here's the mental model that makes it make sense.
This is a supporting guide in the Encoding vs Encryption vs Hashing cluster.
Characters vs bytes
A computer stores bytes (numbers 0–255), not letters. A character encoding is the agreed mapping between characters and the bytes that represent them. If the writer and reader disagree on the encoding, the reader turns the bytes back into the wrong characters — that's where garbled text comes from.
ASCII: the original 128
ASCII maps 128 characters — English letters, digits, punctuation, and control codes — to the numbers 0–127, each fitting in a single byte. A is 65, a is 97, 0 is 48. It's simple and universal, but 128 slots can't hold é, π, 中, or 😀.
Unicode: one number per character
Unicode is a giant catalog that gives every character — across every language, plus symbols and emoji — a unique number called a code point, written like U+00E9 for é. Crucially, Unicode is not an encoding: it says which number a character has, not how to store that number as bytes. That second job is what UTF-8 does.
UTF-8: how those numbers become bytes
UTF-8 is the dominant way to encode Unicode code points into bytes. Its trick is being variable-width:
- Code points 0–127 (plain ASCII) use 1 byte — so UTF-8 is backward-compatible with ASCII.
- Other characters use 2–4 bytes.
So é (U+00E9) is two bytes in UTF-8. If a reader wrongly interprets those two bytes as two separate Latin-1 characters, you see é — classic mojibake. The fix is almost always: make sure everything declares and uses UTF-8.
Where this meets encoding tools
Byte-level encodings build on this. Base64 encodes the bytes of a string — so it has to know the text's encoding first (UTF-8 today). URL/percent-encoding escapes bytes too: a space becomes %20, and é becomes %C3%A9 — those are its two UTF-8 bytes, percent-escaped.
Related
See URL Encoding Explained and What Is Base64 Encoding?, or step back to the pillar: Encoding vs Encryption vs Hashing.
Try it
Percent-encode some accented text or an emoji in the URL Encoder/Decoder and watch each character become its UTF-8 bytes — all in your browser.