The basics
What is a CSV file?
A CSV file stores a table as text. Each line is a row, and commas separate the cells. Because it's so simple, almost every program that handles data can export and import it: banks, accounting software, CRMs, analytics tools, databases, mailing list services and every spreadsheet app.
That makes CSV the common language for moving data between systems that have nothing else in common. It is also why so many CSV problems are about the program at the other end, not the file.
Three things a CSV file is not:
- Not a spreadsheet. It has no formatting, formulas, column widths, charts or multiple sheets. Save a workbook as CSV and all of that is gone, and only the active sheet is saved.
- Not typed. Every field is text. Whether
00742,1/2orTRUEis read as text, a number, a date or a boolean is decided by the program opening it. - Not one strict standard. RFC 4180 describes the format most programs follow, but it is informational, and real files vary in separator, quoting, encoding and line endings.
Anatomy
What's inside a CSV file
A CSV file has no tags or structure beyond lines and separators. Everything else, including which columns exist and what type each holds, is convention. Here is a small file that uses every rule, part by part.
id,name,city,amount,note
00042,Ada Example,Utrecht,12.50,
00043,"Example, Ben",Leeds,7.00,"Said ""hi"""
00044,Cleo Example,Lyon,3.25,"Line one
line two"
00045,Dev Example,Porto,,Paid in cash- 1
id,name,city,amount,noteThe header row
Optional, and nothing in the file says whether it's there: the reading program has to know or guess. When present, it should have as many fields as every other row.
- 2
00042,Ada Example,Utrecht,12.50,A record
One line, one record. Spaces are part of the field:
Ada Examplekeeps its space, and a space after a comma would be kept too. - 3
00042Leading zeros
Stored exactly as written. CSV has no types, so whether this stays
00042or becomes the number42depends entirely on the program that opens it. - 4
12.50,An empty last field
A comma followed by nothing is an empty field. The line still has five fields. CSV can't tell an empty string from a missing value.
- 5
"Example, Ben"A quoted field
A field that contains the separator must be wrapped in double quotes, or the comma would split it in two.
- 6
"Said ""hi"""A quote inside a field
Inside a quoted field, a double quote is written twice. This field's value is
Said "hi". Backslash escapes are not part of CSV. - 7
"Line one line two"A line break inside a field
Allowed inside quotes. This record spans two lines of the file, which breaks any tool that reads CSV one line at a time.
- 8
Porto,,Paid in cashAn empty field in the middle
Two separators with nothing between them. The amount is empty, not zero.
- 9
(the end of each line)Line endings
RFC 4180 specifies CRLF (
\r\n), the Windows convention. Files made on macOS and Linux often use LF alone, and most readers accept both. A final line break after the last record is optional.
RFC 4180
The rules: quoting, commas and line breaks
RFC 4180 was written in 2005 to document how most programs already wrote CSV. Its rules:
- 1Each record is on its own line, ending with CRLF. The last line's line break is optional.
- 2The first line may be a header with the column names, in the same format as the records.
- 3Fields are separated by commas. Every line should have the same number of fields, and there's no comma after the last one.
- 4Spaces are part of a field and should not be ignored.
- 5Any field may be enclosed in double quotes.
- 6A field that contains a comma, a double quote or a line break must be enclosed in double quotes.
- 7A double quote inside a quoted field is written as two double quotes.
| The value | Written in CSV as |
|---|---|
Ada Example | Ada Example |
Example, Ben | "Example, Ben" |
Said "hi" | "Said ""hi""" |
| Two lines of text | The text in quotes, with the line break inside them |
| An empty value | Nothing between two commas |
indented (leading spaces) | indented, or quoted; the spaces stay either way |
Write CSV with a library, not string joins
Joining values with commas breaks the moment a value contains a comma, quote or line break. Every mainstream language has a CSV library (Python's csv module, for example) that applies the quoting rules for you, on writing and on reading.
Troubleshooting
Why is my CSV all in one column, or full of é?
A CSV file doesn't record which separator or encoding it uses. The program opening it has to assume, and Excel's assumptions depend on your computer's settings.
- Everything in column A. Excel on Windows splits on the list separator from your regional settings. In countries that write decimals with a comma, such as the Netherlands, Germany and France, that separator is a semicolon, so a comma-separated file lands in one column. The reverse happens too: a semicolon file from a Dutch colleague opens as one column in a UK or US Excel. Use Data, From Text/CSV, which lets you pick the separator.
- Accents and other scripts garbled.
ébecomingémeans a UTF-8 file was read as an older Windows encoding. Excel often does this when you double-click a UTF-8 CSV that has no byte order mark (BOM). Saving with "CSV UTF-8" in Excel adds the BOM, and importing with From Text/CSV lets you choose UTF-8. - A strange first column name. The opposite problem: a program that doesn't expect a BOM reads its three bytes (
EF BB BF) as part of the first header, soidbecomes\ufeffidorid. Python reads it correctly withencoding="utf-8-sig". - Decimal commas. In a semicolon CSV,
12,50means twelve and a half. Read with the wrong locale, it becomes1250or text.
Uploading a CSV from a Windows computer often sends it as application/vnd.ms-excel instead of text/csv, because that is the type Excel registers for the extension. Upload forms that only accept text/csv reject these files.
Spreadsheet quirks
Why does Excel change my leading zeros, long numbers and dates?
When Excel opens a CSV, it converts each field it can into a number or date. That's useful for prices and unhelpful for postcodes, account numbers and product codes. Microsoft documents these conversions:
| In the file | What Excel may show | Why |
|---|---|---|
00742 | 742 | Read as a number, so leading zeros go. |
1234567890123456789 | 1.23457E+18 | Excel keeps 15 significant digits; the rest become zeros. |
1E5 | 1.00E+05 | Read as scientific notation. |
MARCH1, JAN1 | A date | Letters followed by a number look like a month and day. |
1/2, 3-4 | A date | Which month and day depends on your locale. |
- Turn the conversions off. Excel for Microsoft 365 and Excel 2024 have Automatic Data Conversion settings (on Windows, File, Options, Data) to keep leading zeros, long numbers,
Enotation and date-like text as text. - Import instead of opening. Data, From Text/CSV lets you set a column's type to Text before the data loads. Formatting the column afterwards doesn't bring lost zeros or digits back.
- Don't save over the original. If Excel has already converted the values, saving the CSV again writes the converted values into the file.
sample-excel-traps.csv below holds one example of each, so you can see what your spreadsheet does with them.
Comparison
CSV vs XLSX, TSV and JSON
| CSV | TSV | XLSX | JSON | |
|---|---|---|---|---|
| What it is | Text, comma-separated | Text, tab-separated | ZIP of XML files | Text, nested objects and lists |
| Data types | None | None | Numbers, text, booleans, formulas; dates are formatted numbers | String, number, boolean, null |
| Multiple tables | No | No | Yes, as sheets | Yes, nested |
| Formatting | No | No | Yes | No |
| Quoting needed | For commas, quotes, line breaks | Rarely: tabs seldom appear in data | No | Strings always quoted |
| Readable in a text editor | Yes | Yes | No | Yes |
| Best for | Moving tables between systems | Data with lots of commas | Workbooks people edit | APIs and nested data |
Choose CSV when another program will read the data. Choose XLSX when a person will work with it in a spreadsheet and the types, formatting or several sheets matter.
How to
How to open, edit and convert a CSV file
- Excel (Windows and Mac): double-clicking opens it with Excel's automatic conversions. For control over separator, encoding and column types, start a blank workbook and use Data, From Text/CSV.
- Google Sheets: File, Import, Upload. Choose the separator, and untick "Convert text to numbers, dates, and formulas" to keep values exactly as written.
- LibreOffice Calc: opening a CSV shows a Text Import dialog where you set the character set, separators and each column's type before anything is converted.
- Numbers (Mac, iPhone, iPad) opens CSV files directly.
- A text editor shows the file exactly as it is, which is the quickest way to check the separator, quoting and whether there is a BOM. Browsers usually download a CSV link rather than display it.
- Convert it: save from any spreadsheet app as XLSX, or use a library such as Python's
csvmodule or pandas to turn it into JSON, SQL or anything else.
Security
Is a CSV file safe? CSV injection
A CSV file is plain text and can't contain macros. But a spreadsheet treats a cell that starts with = as a formula. If a website exports user-supplied data to CSV without escaping it, someone can type a formula into a form field and have it run on the computer of whoever opens the export. This is called CSV injection or formula injection.
- What it can do: formulas such as
HYPERLINKcan send the contents of other cells to an outside website when clicked, and older attacks used formulas that launch programs, behind security warnings that people click through. - Dangerous first characters: OWASP lists
=,+,-,@, tab, carriage return and line feed, and full-width variants like=, which some locales treat as formulas. - Escaping: OWASP suggests quoting every field and prefixing each one with an apostrophe, or putting a tab inside the quotes before risky values, which it found more reliable in Excel. No escape is safe for every spreadsheet and every program that later reads the file, so weigh it against data that legitimately starts with
-or+, such as negative numbers and phone numbers.
If you export data other people entered, escape it on export. If you receive a CSV, open it in a text editor or import it as text when you don't trust the source, and don't enable content or click links in a spreadsheet you weren't expecting.
Free downloads
Sample CSV files to download
Free sample CSV files for testing importers, uploads, encodings, spreadsheet behaviour and size limits. Each one parses cleanly with Python's csv module in strict mode, with the same number of fields on every row.
Loading…What's inside sample-orders.csv
CSV has no comments, so every test case is in the data itself. Open the file in a text editor to see these parts exactly as written.
Row 1: the header
Eight column names. Every record that follows has exactly eight fields.
The order_id column
Codes with leading zeros, such as
000184. A spreadsheet that converts them to numbers shows184.The date column
ISO 8601 dates (
2026-10-27), the only date format that every locale reads the same way.Order 000185: commas and quotes
"Example, Ben"and"T-shirt, size M"are quoted because they contain commas; the note"Asked for ""gift wrap"""shows doubled quotes.Order 000186: a line break inside a field
The note runs over two lines of the file but is one field, so the file has 8 lines but only 7 rows, counting the header.
Empty fields and spaces
Two orders have an empty note, and order 000188's note starts with two spaces that a correct reader keeps.
Encoding and line endings
UTF-8 without a BOM (
Cléo,Gdańsk) and CRLF line endings, as RFC 4180 describes. Double-click it in Excel to see whether the accents survive.
All sample CSV files
Sample orders (RFC 4180)
sample-orders.csv · 559 bytes
Six orders that use every quoting rule: commas, doubled quotes and a line break inside fields, empty fields, leading zeros and leading spaces. UTF-8, CRLF line endings.
- Testing a CSV importer or parser
- Teaching the CSV quoting rules
UTF-8 with BOM
sample-utf8-bom.csv · 627 bytes
Greetings in 13 languages plus symbols and emoji, saved as UTF-8 with a byte order mark, the form Excel's "CSV UTF-8" option writes.
- Checking Excel opens UTF-8 correctly
- Testing that importers strip the BOM
Semicolon-separated (European)
sample-semicolon.csv · 245 bytes
Dutch-style invoices: semicolons between fields, decimal commas (
1.234,56), day-first dates and a quoted field that contains a semicolon.- Testing separator detection
- Locale-aware number and date parsing
Values spreadsheets convert
sample-excel-traps.csv · 660 bytes
One value per row that spreadsheets tend to change on opening: leading zeros, a 19-digit number,
1E5,MARCH1,1/2, a time, a percentage,(1234)andTRUE, each with a note on what may happen.- Seeing what Excel or Sheets does to your data
- Checking import settings
Harmless formula injection payloads
sample-formula-injection.csv · 641 bytes
Cells starting with
=,+,-,@and a full-width=, aHYPERLINKformula pointing atexample.com, and the escaped forms OWASP suggests. None of them does anything harmful.- Testing that exports escape formulas
- Checking how a spreadsheet treats each prefix
1 MB CSV file
sample-1mb.csv · 1 MB (1,048,576 bytes)
A header and 14,578 rows of fictional orders, with LF line endings, padded to exactly 1,048,576 bytes (1 MiB).
- Upload and size-limit tests
- Import performance
Ways to test with them
- Quoting: import
sample-orders.csvand count the rows. Seven, including the header, is right; eight means the importer split order 000186 at the line break inside its note. - Excel behaviour: open
sample-excel-traps.csvby double-clicking, then again with Data, From Text/CSV and the column set to Text, and compare. - Export escaping: put the values from
sample-formula-injection.csvinto your app's form fields, export to CSV, and open the export in a spreadsheet. No cell should calculate. - Size limits:
sample-1mb.csvis exactly 1,048,576 bytes, so you can test an upload limit right at the boundary.
Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.
Put it online
Have a CSV file? Give it a link.
Drop a CSV file on 99helpers and it gets its own web address. People can download it into Excel, Google Sheets or their own code, and scripts can fetch it from the same link.
Questions
CSV files, frequently asked
What does CSV stand for?
Comma-Separated Values: the values in each row are separated by commas.
How do I open a CSV file?
Double-click it to open it in your spreadsheet app, or open it in a text editor to see it exactly as written. To control the separator and column types in Excel, use Data, From Text/CSV.
Why does my CSV open in one column in Excel?
The file's separator doesn't match the list separator in your regional settings: usually a comma file on a computer set up for semicolons, or the reverse. Import it with Data, From Text/CSV and choose the separator.
How do I keep leading zeros in a CSV?
The zeros are in the file; the spreadsheet removes them when it opens it. Import the column as Text, or in Excel for Microsoft 365 turn off the leading-zeros conversion under Automatic Data Conversion.
Why are the accents in my CSV wrong?
The program read UTF-8 text as a different encoding. Save the file as UTF-8 with a BOM (Excel's "CSV UTF-8" option), or import it and choose UTF-8 as the encoding.
What's the difference between CSV and XLSX?
CSV is plain text with one table and no types, formatting or formulas. XLSX is Excel's workbook format, which keeps several sheets, formulas, formatting and charts. Any spreadsheet app converts between them.
Can a CSV file contain a virus?
It can't contain macros or programs. It can contain formulas that a spreadsheet runs when you open it, which is called CSV injection, so open CSVs from unknown sources in a text editor or import them as text.
What is the maximum size of a CSV file?
The format has no limit. Excel loads at most 1,048,576 rows into a sheet, so bigger files need to be split, loaded with Power Query, or processed with a database or script.
Related formats
Other file types explained
Keep going
Related
Sources
- RFC 4180: Common Format and MIME Type for CSV Files
- RFC 7111: URI Fragment Identifiers for the text/csv Media Type
- IANA media type registration: text/csv
- Microsoft: Set automatic data conversions in Excel
- Microsoft: Import or export text (.txt or .csv) files
- OWASP: CSV Injection
Last reviewed 27 October 2026.