PrivateCSV

What is a CSV file?

A CSV file (comma-separated values) is a plain-text file that stores a table: each line is one row, and the values in a row are separated by commas. The first line usually holds the column names. Because it is just text, almost every program can read and write it: Excel, Google Sheets, databases, banks, online stores and programming languages.

Last updated

A CSV file example

Here is a small CSV file with a header row and three customers. Each line is a row; each comma starts a new column.

customers.csv
id,name,email,city,joined
1001,Ana García,[email protected],Madrid,2024-01-15
1002,Liam O'Brien,[email protected],Boston,2024-02-03
1003,"Sato, Kenji",[email protected],Tokyo,2024-03-21

Opened in a spreadsheet, the same file is this table:

The example CSV file shown as a table
idnameemailcityjoined
1001Ana García[email protected]Madrid2024-01-15
1002Liam O'Brien[email protected]Boston2024-02-03
1003Sato, Kenji[email protected]Tokyo2024-03-21

Notice the third row: the name contains a comma, so it is wrapped in double quotes. That is how CSV keeps a comma inside a value from starting a new column.

The CSV format rules

CSV has no single owner, but the common rules are written down in RFC 4180, and every major program follows them:

  • One record per line. Lines end with a line break (CRLF on Windows, LF elsewhere; both are read).
  • Values are separated by a delimiter, usually a comma. Every row should have the same number of values.
  • The first line is often a header with the column names. It is optional, and nothing in the file says whether it is there.
  • A value that contains the delimiter, a double quote or a line break is wrapped in double quotes.
  • A double quote inside a quoted value is written twice: "" stands for one ".
  • Spaces are part of the value. Nothing is typed: 007, 3.50 and 2024-01-15 are just text until a program interprets them.
quoting.csv
product,description,price
P-01,"Mug, ceramic, 350 ml",8.50
P-02,"The ""classic"" notebook",4.20
P-03,"Two-line
note",1.00

The file extension is .csv and the media type is text/csv. Files that use a tab instead of a comma are usually called TSV (.tsv), but many programs save them as .csv or .txt too.

Delimiters and encoding

The “comma” is not always a comma. Excel uses the list separator of your region: in most of Europe and Latin America, where 3,5 is a decimal number, it saves CSV files with semicolons. Tabs and pipes (|) are also common in exports from databases and older systems. Good tools detect the delimiter; when one does not, everything lands in a single column.

The other invisible setting is the character encoding. Today CSV files should be UTF-8, which handles every language. Older Excel versions save “CSV (Comma delimited)” in the computer's local encoding (Windows-1252 in Western Europe and the US), and opening such a file as UTF-8, or a UTF-8 file in an old Excel, garbles accents: García instead of García. Excel recognizes UTF-8 when the file starts with a byte order mark (BOM), which is what “CSV UTF-8” adds when you save.

CSV vs Excel (XLSX)

Differences between CSV and Excel files
CSV (.csv)Excel (.xlsx)
What it isPlain textZipped XML workbook
TablesOneSeveral sheets
Formatting, formulas, chartsNone, values onlyYes
Data typesNone: everything is textNumbers, dates, text, booleans
Opens inAny spreadsheet, text editor or programExcel, Sheets, Numbers, LibreOffice
Size limitNone in the format1,048,576 rows × 16,384 columns per sheet
Best forMoving data between systemsWorking on data and presenting it

To move between the two, use CSV to Excel (which keeps leading zeros and long numbers as text) or Excel to CSV.

What CSV files are used for

  • Exports and imports: bank statements, Shopify and WooCommerce products, Google and Outlook contacts, CRM and mailing lists all use CSV.
  • Moving data between databases, spreadsheets and apps that share no other format.
  • Data analysis: Python (pandas), R, SQL databases and BI tools load CSV directly.
  • Open data: governments and researchers publish datasets as CSV because anyone can open them.

How to open a CSV file

Double-click it to open it in Excel, Numbers or LibreOffice, import it in Google Sheets (File > Import), or open it in a text editor to see the raw text. Double-clicking can drop leading zeros or garble accents; importing lets you choose the delimiter and encoding. The full guide, app by app, is How to open a CSV file.

How to create a CSV file

  1. Excel: File > Save As (or Save a Copy), then choose “CSV UTF-8 (Comma delimited) (*.csv)”. Only the active sheet is saved.
  2. Google Sheets: File > Download > Comma-separated values (.csv).
  3. Numbers (Mac): File > Export To > CSV.
  4. A text editor: type the header line and one line per row, separate the values with commas, and save the file with a .csv extension in UTF-8.
  5. From another format: convert JSON, XML, a text file, a Numbers file or contacts.

Common CSV problems and fixes

Common problems when opening CSV files
ProblemCauseFix
Everything in one columnThe delimiter (often ;) differs from what the program expectsImport the file and choose the delimiter
é instead of éEncoding mismatch (UTF-8 vs Windows-1252)Import as UTF-8, or save with “CSV UTF-8”
Zip codes lose their leading 0Excel reads 02134 as a numberImport the column as Text
1.23E+15 instead of a long numberExcel shows numbers over 11 digits in scientific notation and keeps 15 digitsImport the column as Text
Rows shifted or brokenAn unquoted comma, quote or line break in a valueCheck the file with a CSV validator

The CSV Validator lists rows with the wrong number of columns, quoting errors and encoding problems, and the CSV to Excel converter keeps zeros and long numbers intact.

Frequently asked questions

What does CSV stand for?

CSV stands for comma-separated values. The name describes the format: a table written as text, with a comma between the values of each row and one row per line.

Is a CSV file the same as an Excel file?

No. A CSV file is plain text with one table and no formatting, formulas or charts. An Excel file (.xlsx) is a binary workbook that can hold several sheets, formulas, colors and charts. Excel opens CSV files, but saving a workbook as CSV keeps only the values of the active sheet.

Can a CSV file have multiple sheets?

No. A CSV file holds exactly one table. A workbook with several sheets becomes several CSV files, one per sheet.

What program opens a CSV file?

Excel, Google Sheets, Apple Numbers and LibreOffice Calc open CSV files as tables, and any text editor (Notepad, TextEdit, VS Code) shows the raw text. You can also open one online in a CSV viewer without installing anything.

Why is my CSV file separated by semicolons instead of commas?

In countries that write decimals with a comma (France, Germany, Spain, Brazil...), Excel saves CSV files with semicolons so that 3,5 is not split into two columns. Both are valid; most tools let you choose the delimiter when importing.

Is it safe to open a CSV file?

A CSV file cannot run code by itself, but a cell starting with =, +, - or @ can be read as a formula by a spreadsheet (CSV injection). Be careful with CSV files from unknown senders, and do not enable external content or links Excel asks about.