# What Is RFC 4180? — The CSV Format Rules, Quoting and Line Breaks

Canonical: https://commareports.com/glossary/rfc-4180
Published: 2026-10-17

> RFC 4180 is the closest thing CSV has to a standard: CRLF line breaks, an optional header, double-quoted fields for commas, quotes and newlines, and quotes escaped by doubling. What it says, what it leaves out, and why Excel files still break.

# RFC 4180 (CSV)

**RFC 4180 is the document that defines the common CSV format and
registers the `text/csv` MIME type.** Published in October 2005, it is
_Informational_ — it wrote down what spreadsheets and databases were
already doing rather than imposing a standard — so it is the reference
most parsers aim for, not a guarantee every file follows.

## The rules, in full

1. Each record is on its own line, ended by a line break — **CRLF**
   (`\r\n`).
2. The last record may or may not have a trailing line break.
3. The first line may be a **header** with the same number of fields.
   Whether it is one is signalled out of band, through the MIME type's
   `header=present|absent` parameter.
4. Every record should have the **same number of fields**. Spaces are
   part of a field and must not be trimmed. There is no comma after the
   last field.
5. Any field may be enclosed in **double quotes**.
6. A field containing a **comma, a double quote or a line break** must be
   enclosed in double quotes.
7. A double quote inside a quoted field is written **twice**: `""`.

```
id,name,note
1,Ada,plain
2,"Lovelace, Ada","said ""hi"""
3,Grace,"two
lines"
```

That file has three records, not four — the line break in record 3 is
inside quotes.

## What it doesn't cover

| Question                      | RFC 4180 says                 | Real files do                                                      |
| ----------------------------- | ----------------------------- | ------------------------------------------------------------------ |
| Delimiter                     | Comma, always                 | `;` in locales where `,` is the decimal separator                  |
| Encoding                      | The `charset` MIME parameter  | UTF-8, UTF-8 with a [BOM](/glossary/byte-order-mark), Windows-1252 |
| Line ending                   | CRLF                          | LF from most Unix tools; parsers accept both                       |
| Escape character              | None — quotes are doubled     | Some tools emit `\"`, which other parsers misread                  |
| Types (numbers, dates, nulls) | Nothing — every field is text | Excel and Sheets guess, and drop leading zeros                     |
| Comments, `sep=` line         | Nothing                       | Excel honours a first line of `sep=;`                              |

Those gaps are where CSV breaks between programs:
[CSV opens wrong in Excel](/fix/csv-opens-wrong-in-excel) walks through
the encoding, separator and type-coercion cases, and
[CSV injection](/glossary/csv-injection) covers the field that starts
with `=`.

## Reading it correctly

Splitting on `\n` and then on `,` fails on rule 6. A correct reader is a
small state machine — inside quotes or not — and every standard library
has one: Python's `csv`, Go's `encoding/csv`, PapaParse or `d3.csvParse`
in JavaScript. Writing is simpler: quote a field when it contains a
comma, quote or line break, and double any quotes inside it.

Comma's free converters follow these rules in both directions —
[CSV to JSON](/tools/csv-to-json), [JSON to CSV](/tools/json-to-csv),
[HTML table to CSV](/tools/html-table-to-csv) and
[CSV to HTML table](/tools/csv-to-html-table).

## Try it

Comma is free — unlimited reports, unlimited commenters, unlimited
revision history.

**[Turn a CSV into a shareable table →](/tools/csv-to-html-table)**

### Related

- [Byte order mark](/glossary/byte-order-mark) · [CSV injection](/glossary/csv-injection) · [NDJSON](/glossary/ndjson) · [MIME type](/glossary/mime-type)
- [CSV opens wrong in Excel](/fix/csv-opens-wrong-in-excel)
- [Glossary](/glossary)
