CSV Files Explained
The CSV format in depth — RFC 4180 quoting rules, delimiters, encodings, common pitfalls, and how CSV compares to TSV, JSON and Parquet.
Last updated: 26 July 2026
CSV (Comma-Separated Values) is the most common plain-text format for tabular data. It is human-readable, tiny, and supported by virtually every spreadsheet, database and programming language — which is exactly why it is everywhere, from data exports to API dumps.
Structure
A CSV file is just text: each line is a record (row), and each row is split into fields (columns) by a delimiter — usually a comma. The first row is conventionally a header naming the columns.
id,name,city
1,Ana,Mumbai
2,Ravi,Delhi
There is a loose standard, RFC 4180, that most tools follow.
Quoting & escaping (the tricky part)
Plain splitting on commas breaks as soon as a value contains a comma, a quote or a newline. RFC 4180 solves this with double quotes:
- A field that contains a comma, double quote or line break must be wrapped in double quotes:
"Doe, John". - A literal double quote inside a quoted field is written as two double quotes:
"She said ""hi""". - A quoted field may span multiple lines — the newline is part of the value, not a new row.
id,note
1,"Contains, a comma"
2,"Contains ""quotes"" too"
3,"Spans
two lines"
Getting this right is the single most common source of CSV bugs. Our tools implement RFC-4180 quoting, so pasted data with commas and newlines round-trips correctly.
Delimiters
The “C” is only a convention. Common alternatives:
| Delimiter | Name | When to use |
|---|---|---|
, |
Comma (CSV) | The default, most widely supported |
\t |
Tab (TSV) | Data full of commas; simpler quoting |
; |
Semicolon | Common in locales where the comma is the decimal separator |
| |
Pipe | Logs and data that may contain commas and semicolons |
Most CodingSetu CSV tools let you choose the delimiter.
Encoding
CSV is just bytes, so encoding matters. Use UTF-8. A UTF-8 BOM (byte-order mark) can help Excel auto-detect the encoding, but many parsers treat the BOM as data if they don’t strip it — our parser strips a leading BOM automatically.
Common pitfalls
- Excel type coercion — leading zeros dropped (
007→7), values turned into dates (1-2), long IDs shown in scientific notation. Import as Text or validate the raw file instead of double-clicking it. - Inconsistent column counts — a stray comma or missing quote shifts every following column. Use a validator to catch rows whose column count doesn’t match the header.
- Mixed line endings (
\nvs\r\n) — usually harmless, but some naive parsers choke. Ours handles both. - No header — if the first row is data, tools that key on column names can’t help; add a header row first.
CSV vs other formats
| Format | Human-readable | Types | Nested data | Size | Best for |
|---|---|---|---|---|---|
| CSV | Yes | No (all text) | No | Small | Interchange, spreadsheets |
| TSV | Yes | No | No | Small | Comma-heavy data |
| JSON | Yes | Yes | Yes | Larger | APIs, nested structures |
| Parquet | No (binary) | Yes | Yes | Very small | Analytics at scale |
CSV wins on ubiquity and simplicity; reach for JSON when you need types or nesting, and Parquet when you need columnar analytics performance.
Best practices
- Always include a header row with clear, unique column names.
- Quote defensively — quote any field that could contain a delimiter, quote or newline.
- Stick to UTF-8; document whether you emit a BOM.
- Keep one table per file; use consistent column counts.
- Validate before you rely on a CSV in a pipeline.
Work with CSV in your browser
Every CodingSetu CSV tool runs entirely client-side — your files are never uploaded. Convert, clean, filter, analyze, split, merge and compare CSV with the tools below.
References
- RFC 4180 — the Common Format and MIME Type for CSV files.
- MDN: text/csv — MIME types overview.
Frequently asked questions
What does CSV stand for?
CSV stands for "Comma-Separated Values" — a plain-text format where each line is a record and fields within a record are separated by commas (or another delimiter).
How do I put a comma inside a CSV field?
Wrap the whole field in double quotes, e.g. "Doe, John". Any field that contains a comma, a double quote or a line break must be quoted. A literal double quote inside a quoted field is escaped by doubling it ("").
Why does Excel mangle my CSV (leading zeros, dates, big numbers)?
Excel auto-detects types, so "007" becomes 7, "1-2" becomes a date, and long digit strings become scientific notation. To avoid this, import via Data → From Text/CSV and set columns to Text, or keep values quoted and validate the raw CSV with a dedicated tool rather than opening it directly.
Is TSV better than CSV?
TSV (tab-separated) avoids the comma-quoting problem because tabs rarely appear in data, so it is often simpler to parse. CSV is more widely supported. Both are row/column text formats; pick TSV when your data is full of commas.
What encoding should a CSV use?
UTF-8. If a tool requires it, a UTF-8 BOM can help Excel detect the encoding, but most modern parsers handle UTF-8 without a BOM. Avoid legacy encodings like Latin-1 unless you must.