What is UTF-8?
Short answer
UTF-8 is a way to store text as bytes that can represent every character in Unicode, from plain English letters to accents and emoji. It is backward compatible with ASCII and is the dominant text encoding on the web.
Characters, code points, and bytes
Unicode assigns every character a number called a code point. UTF-8 is one way to turn those numbers into bytes for storage and transmission. It uses one to four bytes per character, spending more bytes only on rarer or more complex characters.
- ASCII characters (A-Z, digits, punctuation) take a single byte
- Accented Latin and many scripts take two bytes
- Most other scripts take three bytes
- Emoji and rare characters take four bytes
Why it matters
When the encoding is wrong, text turns into garbled symbols, sometimes called mojibake. Declaring UTF-8 everywhere keeps characters, including emoji and names with accents, correct from input to display. A character is not always one byte, which is why byte counts and character counts can differ.