Every text character — a letter, a digit, an emoji — is stored as bytes. The map from characters to bytes is called a character encoding. This guide explains the differences and how to avoid the classic "mojibake" garbled text issue.
1. ASCII — the original 128 characters
ASCII (1963) defined 128 characters: 0–9, A–Z, a–z, common punctuation, and a few control codes. Each character fits in 7 bits. ASCII was enough for English but not for other languages.
2. Unicode — one code point per character
Unicode (1991) assigns a unique number (called a code point) to every character in every language: Latin, Cyrillic, CJK, Arabic, emoji, ancient scripts, and more. Currently over 150,000 characters are defined.
3. UTF-8 — the dominant encoding on the web
UTF-8 is a variable-width encoding that stores each Unicode code point as 1–4 bytes. ASCII characters use 1 byte (so UTF-8 is backward compatible), and other characters use 2–4 bytes. Over 98% of web pages use UTF-8 today.
4. What is mojibake?
Mojibake is garbled text that appears when a file is decoded with the wrong encoding. Common symptoms: ã© instead of é, or ??? for unrecognized characters. The fix is to ensure the file is saved as UTF-8 and the application reads it as UTF-8.
5. How to debug
- Check the file is saved as UTF-8 (no BOM unless needed)
- Check the HTTP header
Content-Type: text/html; charset=utf-8 - Check the HTML
<meta charset="utf-8">tag is the first thing in<head> - Use the Character Counter to inspect the raw bytes