You open a CSV and every “é” has become “é”. A rupee sign turns into “₹”. A Hindi name shows as a row of question marks or empty boxes. A database rejects an emoji. All of these are the same problem: text was written in one character encoding and read in another. This guide explains how computers store text, why UTF-8 won, and how to recognise and fix the most common encoding bugs.
Characters, code points and bytes
Computers store bytes, not letters, so every piece of text needs a rule that maps characters to numbers and numbers to bytes. Two layers are involved:
- Unicode gives every character a number called a code point, written like U+0041 for “A”, U+00E9 for “é”, U+20B9 for “₹” and U+0928 for “न”. It covers virtually every script in use, plus symbols and emoji.
- An encoding turns those code points into bytes. UTF-8 is by far the most common; others include UTF-16 (used inside Windows, Java and JavaScript strings) and older single-byte encodings such as Windows-1252 and ISO-8859-1 (Latin-1).
Unicode is the list of characters; UTF-8 is one way of writing them down. Mixing up the two is behind much of the confusion.
How UTF-8 works
UTF-8 uses one to four bytes per character. The first 128 code points — the ASCII letters, digits and punctuation — use a single byte with the same value as in ASCII, which is why plain English text looks identical in ASCII and UTF-8. Everything else uses more bytes:
| Character | Code point | UTF-8 bytes (hex) | Bytes |
|---|---|---|---|
| A | U+0041 | 41 | 1 |
| é | U+00E9 | C3 A9 | 2 |
| ₹ | U+20B9 | E2 82 B9 | 3 |
| न (Devanagari na) | U+0928 | E0 A4 A8 | 3 |
| 👍 | U+1F44D | F0 9F 91 8D | 4 |
The design has useful properties: ASCII files are already valid UTF-8, no character’s bytes can be mistaken for part of another, and a damaged byte affects only one character. It is the default for the web, JSON, most programming languages and modern operating systems, and it is the right choice for any new file.
Mojibake: garbled text and how to read it
When UTF-8 bytes are read as Windows-1252 or Latin-1, each byte becomes its own character, and you get the distinctive garbage called mojibake:
| Written (UTF-8) | Read as Windows-1252 |
|---|---|
| café | café |
| ₹ 500 | ₹ 500 |
| “quoted” | “quoted†|
| it’s | it’s |
If you see à or †scattered through text, it is almost always UTF-8 being misread. The fix is to re-open the file and tell the program it is UTF-8 — not to find-and-replace the garbage, which is slow and misses cases.
The opposite mistake — a Windows-1252 file read as UTF-8 — produces the replacement character � (often shown as a black diamond with a question mark), because the old single bytes are not valid UTF-8. That one can only be fixed by re-reading the original file with the right encoding; once the text has been saved with � in it, the original letter is gone.
Question marks (?) in place of Hindi, Tamil or Chinese text usually mean the text passed through a system that could not represent those characters and replaced them, typically a database column or a program set to an old encoding. Empty boxes (□), on the other hand, usually mean the text is fine but the font has no glyph for it.
Excel and CSV files
CSV is the most common place to meet encoding bugs, because a CSV file has no way to say what encoding it uses. Practical rules:
- Save as “CSV UTF-8”. Recent versions of Excel offer this explicitly. Older “CSV” options save in the computer’s legacy encoding and lose non-English characters.
- Opening UTF-8 CSVs in Excel by double-clicking can still produce mojibake. Use Data → From Text/CSV and choose UTF-8 (code page 65001), or make sure the file starts with a UTF-8 byte-order mark (BOM), which Excel uses as a hint.
- The BOM is three invisible bytes (
EF BB BF) at the start of a file. Excel likes it; some programs and scripts do not and show it as “” before the first column name, which breaks lookups on that column. SnipFerry’s data tools strip it automatically.
Our guide How to Clean Messy CSV Data covers the other common CSV problems.
Why one character can count as two, three or eight
“How long is this text?” has several honest answers, and different systems use different ones. Take the thumbs-up emoji with a skin tone, 👍🏽:
- 1 user-perceived character (a grapheme) — what a person would count.
- 2 Unicode code points — the thumbs-up plus a skin-tone modifier.
- 4 UTF-16 code units — what JavaScript’s
.lengthand Java’slength()report. - 8 UTF-8 bytes — what matters for storage, network limits and many database column sizes.
Indian scripts behave similarly. “नमस्ते” is 6 code points and 18 UTF-8 bytes; current browsers count it as 3 user-perceived characters (न, म and the conjunct स्ते), and some older software says 4. This is why the Character Counter shows user-perceived characters and the UTF-8 byte size side by side, and why SMS messages in Hindi fit fewer characters per message than English ones. How to Count Words and Characters explains the platform limits.
Same text, different bytes: normalisation
Some characters can be written two ways. “é” can be the single code point U+00E9, or a plain “e” followed by a combining accent (U+0065 U+0301). Both look identical, but they are different bytes, so a search, a join or a duplicate check treats them as different values. macOS file names and text copied from some PDFs often use the decomposed form.
Unicode defines normalisation forms to fix this: NFC (composed, the usual choice for storage and comparison) and NFD (decomposed). Most programming languages have a one-line way to normalise, such as JavaScript’s text.normalize('NFC'). If two values that look the same refuse to match, normalisation — or an invisible character such as a non-breaking or zero-width space — is a likely cause.
Encodings that are not character encodings
Several things called “encoding” are different layers on top of the bytes, and each one assumes UTF-8 underneath:
- URL (percent) encoding writes each UTF-8 byte as
%XX, so “₹” becomes%E2%82%B9. See URL Encoding Explained and the URL Encoder. - Base64 turns any bytes into plain ASCII letters; “₹” becomes
4oK5. Naive encoders that skip UTF-8 break on non-English text. See Base64 Explained and the Base64 tool. - HTML entities write a character by its code point, such as
₹for ₹ oréfor é. The HTML Entity Encoder converts both ways. - JSON escapes such as
\u00e9also refer to code points. JSON files themselves must be UTF-8.
A checklist for text that survives
- Use UTF-8 everywhere: files, databases, HTTP responses and HTML (
<meta charset="utf-8">). - In MySQL, use the
utf8mb4character set. The olderutf8stores at most three bytes per character and rejects emoji. - Decide what “length” means before you enforce a limit — characters for people, bytes for storage — and test with emoji and Indian-language text.
- Normalise to NFC and trim invisible spaces before comparing or de-duplicating text.
- When you see à or â€, fix the reading step, not the text.