scalpel@labs: ~/glossary/csv-file-format.mdx5 sections

CSV File Format: What It Is and How Quoting Works

CSV (comma-separated values) is a plain-text table: one record per line, fields separated by commas. RFC 4180 sets the rules, most importantly that a field holding a comma, a double quote or a line break is wrapped in double quotes, with inner quotes doubled.

extension: Scalpel Tablesupdated: 2026-08-14read_time: 3 min
less csv-file-format.mdx

Why it matters

CSV is the most portable data format. Every spreadsheet, database tool, and programming language reads it. But portability comes with rules. A field holding a comma or a quote needs special handling, or the parser breaks. RFC 4180 defines the standard so every tool agrees on what the bytes mean. Ignore the rules and your data corrupts or fails to import.

How it works

A CSV file is plain text. Each line is a record. Fields on a line are separated by commas. If a field holds a comma, a double quote, or a line break, the whole field is wrapped in double quotes. Any double quote inside the field is written twice: " becomes "".

Here is the full rule set from RFC 4180:

  1. Each record is one line ending with CRLF (\r\n), or on the final record, just the end of file.
  2. Fields are separated by a comma.
  3. A field containing commas, quotes, or line breaks must be wrapped in double quotes.
  4. Inside a quoted field, any " is escaped as "" (two quotes).
  5. There is no escape character for other things; backslash has no special meaning.

Line endings in a CSV are CRLF (\r\n) by spec, though most tools accept either LF (\n) or CRLF on read. Many tools write LF only because it is simpler, and parsers are lenient.

What does not matter

CSV has no built-in data types. A cell that looks like "123" is text; a cell that is 123 without quotes is text too. The spreadsheet program on open might guess: "that looks like a number," but the CSV itself makes no promise. That is why a code like 007 should be written as "007" if you want to preserve the leading zero when someone opens it in Excel.

CSV is not an Excel format. Excel is one reader. Excel has a habit of mangling dates on import: it sees 2/5/2026 and converts it to a date serial, even if you wanted the text "2/5/2026." That is an Excel quirk, not a CSV rule. Semicolon-delimited files are sometimes called "CSV" in locales where the comma is a decimal separator, but the standard is comma-delimited.

Code example

Here is a row with an embedded comma, an embedded double quote, and a line break:

"Product name with a comma, Ltd.","Quote: ""Best tool ever""","Note:
Line two"

Broken into fields:

  1. Product name with a comma, Ltd.
  2. Quote: "Best tool ever"
  3. Note: (line break) Line two

Each field is quoted because it holds a special character. The double quotes inside the second field are doubled in the raw bytes: "" reads as a single ". The third field has a literal line break; the parser knows to keep reading until it sees the closing quote.

Here is the same data in raw bytes (simplified):

"Product name with a comma, Ltd.","Quote: ""Best tool ever""","Note:
Line two"

How Scalpel shows it

The CSV button on each table card downloads an RFC 4180 compliant file. Scalpel wraps any field holding a comma, quote, or line break. The file opens cleanly in Excel, Google Sheets, Python, R, and any standard CSV parser.

Sources