CSV Encoding Explained: UTF-8, BOM, and How to Fix Garbled Characters
Fix CSV files that show é as é or fill with question marks. Learn how UTF-8, BOM and Windows-1252 differ, and how to repair and prevent encoding problems.
You open a CSV and your customer list is full of nonsense. José has become José. The apostrophe in every company name is now ’. Somebody in the list is called “M�ller” and you’re fairly sure that’s not how the name is spelled.
Nothing is wrong with the data, which is the part that’s easy to forget when you’re staring at it. The text is almost always still intact in the file. What went wrong is that one program wrote it using one set of rules and another program read it using a different set. If you work out which rules were used, you can usually get everything back.
This guide explains what encoding is without the jargon, which ones show up in CSV files, how to read the symptoms, and how to fix a file. I’ll also cover the byte order mark, which causes its own set of problems, and a few habits that stop this from happening again.
What’s actually going on
A file doesn’t contain letters. It contains numbers, one byte at a time, and an encoding is the lookup table that says which letter each number stands for. For plain English text, every common table agrees: the byte 65 means “A” in all of them. They only disagree once you move past the basics, into accents, curly quotes, currency symbols and non-Latin alphabets.
Take the name José. The letter é is stored in UTF-8 as two bytes, C3 A9. A program that knows the file is UTF-8 reads those two bytes together and shows é. A program that assumes Windows-1252, which stores one character per byte, reads them separately: C3 is à and A9 is ©. You see “José”.
The file didn’t change between those two readings. Only the guess did. That’s the key idea, and it’s why most garbled files are fixable: the bytes are fine, and you just need to read them with the right table.
The catch is that a CSV has no place to say which encoding it uses. There’s no label in the header, no setting stored with it. Every program has to guess, or fall back on a default, and different programs have different defaults.
The encodings you’ll actually meet
You don’t need to memorise all of them. These are the ones that show up in real CSV files.
UTF-8. The modern standard. It can represent every character in every language, including emoji. English letters take one byte, accented letters two, and most other scripts three or four. If you’re creating a new file, this is the one to use.
UTF-8 with BOM. The same as UTF-8 but with three extra bytes at the start (EF BB BF), called a byte order mark. It exists mostly because Excel on Windows needs it as a hint. More on this below.
Windows-1252. Also called “ANSI” in Windows menus, and the default in many older exports from Windows software. One byte per character, covering Western European languages. It’s very close to ISO-8859-1 (Latin-1), but includes curly quotes, dashes and the euro sign in a range where Latin-1 has control codes. That difference is why smart quotes are often the first thing to break.
UTF-16. Two bytes for most characters. Excel produces it when you choose “Unicode Text” on save, and the file is usually tab-separated rather than comma-separated. If a tool shows letters with gaps between them, or says the file looks binary, UTF-16 is a likely cause.
Regional encodings. Files from older systems in Japan, China, Korea or Eastern Europe may use Shift JIS, GBK, Big5, Windows-1251 and others. If your data is in one of those languages and looks like random symbols, ask where the file came from and try that region’s encoding.
Read the symptom
Each kind of mix-up leaves its own fingerprint, and it’s worth learning to read them, because it tells you what to do next.
à followed by another symbol (José, Müller), or ’ for an apostrophe. The file is UTF-8 and was read as Windows-1252. This is the most common problem by far, and it’s fully fixable: reopen the file as UTF-8.
A diamond with a question mark (�). The reverse: the file was Windows-1252 and a program tried to read it as UTF-8. A single byte like E9 for é isn’t valid UTF-8, so the program substituted a replacement character. The danger is that if you save the file at this point, the replacement character is written into the file and the original letter is gone for good. Reopen the original file as Windows-1252 instead.
 at the very start of the first column name. That’s the byte order mark (EF BB BF) being read as three Windows-1252 characters. The file is UTF-8 with BOM and the reader doesn’t know what to do with the mark.
Literal question marks where letters should be (Jos?). This one’s different. It means the characters were replaced with ? when the file was created, usually because it was exported with an encoding that couldn’t represent them. The information was lost at that point, and no reader can bring it back. You have to export again.
Spaced-out letters, or blocks of unreadable text in a language you can’t identify. Think UTF-16 or a regional encoding.
Why Excel causes so much of this
Most people meet this problem for the same reason: they double-click a CSV and it opens in Excel.
On Windows, when Excel opens a CSV directly, it looks for a byte order mark. If there’s one, it treats the file as UTF-8. If there isn’t, it falls back to the system’s legacy code page, which is Windows-1252 in Western regions. A perfectly good UTF-8 file without a BOM arrives in Excel looking broken.
The reverse also happens. If someone saves from Excel using the plain “CSV (Comma delimited)” option, the file is written in the legacy code page. Names with characters outside that table get question marks, and the file is read wrongly by anything that expects UTF-8.
Newer versions of Excel offer “CSV UTF-8 (Comma delimited)” in the Save As list, which writes a BOM and is the better choice. Our guide on exporting Excel to CSV without corrupting data goes through the export side in detail.
If you don’t have Excel handy, other spreadsheet programs are less fussy. LibreOffice Calc shows a text import dialog every time you open a CSV, with a Character set dropdown you can change while watching the preview, which makes it a good way to test an unknown file. Google Sheets usually reads UTF-8 correctly on import, though it can stumble on legacy encodings. Both are useful for working out what a file really is before you decide on a fix. The one rule that applies everywhere comes next: work on a copy.
How to fix a garbled file
The golden rule: don’t save anything from the garbled view. If you open a file wrongly and then save it, you can bake the damage into the file. Keep the original and work on a copy.
In Excel. Don’t double-click. Open a blank workbook, go to Data, then From Text/CSV, and pick the file. In the preview window, change the File Origin dropdown to “65001: Unicode (UTF-8)” and watch the preview. When the accents look right, load the data. If UTF-8 looks wrong, try the Windows-1252 option instead.
In a text editor. VS Code shows the encoding in the bottom-right corner. Click it, choose “Reopen with Encoding”, and try UTF-8 or Windows-1252 until the text looks right. Then use “Save with Encoding” to write it back as UTF-8. Windows Notepad does the same through its status bar and the Save As dialog.
On the command line. If you know the file is Windows-1252, iconv converts it:
iconv -f WINDOWS-1252 -t UTF-8 export.csv > export_utf8.csv
In Python. A small script that tries UTF-8 first and falls back to Windows-1252 works well, because genuine Windows-1252 text with accents almost never happens to be valid UTF-8, so a successful UTF-8 decode is a strong signal:
from pathlib import Path
raw = Path("export.csv").read_bytes()
try:
text = raw.decode("utf-8-sig") # also strips a BOM if present
except UnicodeDecodeError:
text = raw.decode("cp1252")
with open("export_utf8.csv", "w", encoding="utf-8", newline="") as f:
f.write(text)
Setting newline="" on the output keeps the original line endings unchanged.
If the damage is already saved. Sometimes you inherit a file where “José” is literally what’s stored, because someone already did the misread-and-save round trip. If the text came from a UTF-8 file read as Windows-1252, you can reverse it:
"José".encode("cp1252").decode("utf-8") # gives "José"
This works only when the damage came from that specific mix-up. For messy cases, the ftfy library is built to repair this kind of text. If you see the replacement character (�) or literal question marks in the stored data, though, those can’t be repaired.
A worked example
Say a colleague sends you suppliers.csv and the first rows look like this in Excel:
Name,City
Café Rosa,München
Bakery ’n Bite,Köln
The pattern is à followed by a symbol, plus ’ where an apostrophe should be. That’s the UTF-8 read as Windows-1252 symptom, so the file itself is probably fine. You close it without saving, open a blank workbook, import through Data, then From Text/CSV, and set File Origin to UTF-8. The preview now shows “Café Rosa”, “München”, “Köln” and a normal apostrophe. Load it, and you’re done. If you then need to share the cleaned data, save it as “CSV UTF-8” so the next person doesn’t repeat the problem.
Had the preview shown �, you’d go the other way and try Windows-1252. Two tries is usually all it takes.
The BOM: to include it or not
The byte order mark is the source of a lot of arguments. The practical answer is that it depends on who or what will read the file.
Include it when the audience is people opening the CSV in Excel on Windows by double-clicking. The BOM is what makes Excel treat the file as UTF-8, so accents come through correctly.
Leave it out when the file is going to code, a database import or a command-line tool. Some parsers don’t strip the mark, so it ends up glued to the first header. You get a column called \ufeffid that doesn’t match id, which breaks lookups and merges and is almost impossible to spot by eye. If you’ve ever had a script fail on a column that looked right, this is a classic cause. It’s also one of the checks in our guide to merging multiple CSV files, where a stray BOM creates a duplicate first column.
If you can’t tell who will open the file, UTF-8 with BOM is usually safer for office users, and a note in the email saying so is even better.
Emoji and databases deserve a quick mention too. Emoji need four bytes in UTF-8, and Windows-1252 can’t represent them at all, so they’re the first thing to turn into question marks when a file passes through an older system. MySQL has a classic version of this trap: its utf8 character set only stores three bytes per character, so emoji fail or get cut off, and you need utf8mb4 to store them properly. If your CSV is headed for a database, check the column and connection encodings as well as the file.
Keep it from happening again
A few habits remove almost all of these problems:
- Export as UTF-8 by default. Check the export settings of any system you use regularly. Many have an encoding option hidden in a dropdown.
- Be explicit in code. Whenever you read or write a CSV in Python, pass
encoding="utf-8"rather than relying on the platform default, which differs between machines. - Test with an awkward name. Put a name like “Zoë Müller-Łukasiewicz” in a test row. If it survives a round trip through your process, most real data will.
- Tell recipients how to open the file. One line like “In Excel, use Data → From Text/CSV and choose UTF-8” saves a lot of replies.
- Keep the original file. Whatever repair you do, work on a copy.
Check a file in your browser first
Before you convert or share a CSV, it’s worth a quick look at what it really contains. The CSV viewer opens the file locally in your browser, so nothing is uploaded, and you can scan for accents, apostrophes and non-English names that look wrong. If something looks off, you know about it before it reaches a client or goes into a converter.
If you’re about to turn the data into something else, like an Excel file with the CSV to Excel converter, do this check first. A conversion preserves whatever your file already contains, including the garbled text, so fixing the encoding comes before everything else.
The same applies to files with sensitive data, such as customer names and addresses, which is the other reason to prefer tools that run on your own device. Our post on why you shouldn’t upload sensitive CSVs to cloud converters covers that side.
The short version
Garbled text is almost never lost text. It’s a file read with the wrong table. Learn the symptoms, reopen the original with the right encoding, convert it to UTF-8 once, and keep it that way. The only unfixable cases are literal question marks and the replacement symbol, and those tell you to go back to the source and export again.
Frequently asked questions
Why does my CSV show é as é or ’ as ’?
The file was saved as UTF-8, but the program opening it read the bytes as Windows-1252. UTF-8 stores accented letters and curly quotes as two or three bytes, and Windows-1252 turns each of those bytes into a separate character, which produces the strange sequences. Re-opening the file with UTF-8 selected as the encoding normally fixes it.
What does the BOM do in a UTF-8 CSV file?
A byte order mark is three invisible bytes at the start of the file that tell the reader the text is UTF-8. Excel on Windows uses it to pick the right encoding. The downside is that some databases, scripts and parsers treat those bytes as part of the first column name, so BOM files are best kept for people using Excel and avoided for files that feed code.
Can I recover characters that show as question marks or ���?
Usually not. A literal question mark means the character was already replaced when the file was exported, and a replacement symbol means it was lost when the file was saved after being misread. The original text exists only in the source, so the real fix is to export again with the correct encoding.
Which encoding should I use for CSV files?
Use UTF-8 unless the receiving system demands something else. It covers every language and emoji, and it's the default for most modern software. If the file will be opened by double-clicking in Excel on Windows, add a byte order mark or have the recipient use the import dialog.
How can I tell what encoding a CSV file uses?
There's no label inside the file, so tools can only guess. Open it in a text editor that shows the detected encoding, try UTF-8 first, and switch to Windows-1252 if accented letters look wrong. Command-line tools such as file or Python libraries like charset-normalizer give a best guess, not a certainty.