CSV and delimited text formats: structure and dialect rules

How CSV and other delimited text formats are structured, which dialect rules vary between files, and when converting or auto-detecting a dialect preserves your data.

CSV looks like the simplest data format there is: values separated by commas, one record per line. In practice, files called CSV follow different conventions for delimiters, quoting, line endings and character encoding. This review explains the structure rules, the dialect differences that matter, and how to judge whether a dialect conversion or automatic detection keeps your data intact and usable.

What CSV and delimited text formats mean

CSV stands for comma-separated values. It is a plain-text way to store a table: each line is a record, and each record is split into fields by a delimiter character. The broader family is often called delimited text or DSV (delimiter-separated values), which covers tab-separated files, semicolon-separated exports, pipe-delimited files and colon-separated system files such as the Unix password file.

The most widely cited description of CSV is RFC 4180, an informational document that also registered the text/csv media type. It describes common practice rather than enforcing a strict standard, so many real files and tools depart from it. The set of conventions a particular file follows is usually called its dialect.

Core structure rules

The rules described in RFC 4180 are a useful baseline, even though many tools relax some of them:

  • Each record sits on its own line, ended by a line break (the RFC specifies CRLF; many tools also accept LF alone).
  • An optional header line can name the fields, using the same format as the data lines. Nothing in the file itself marks whether the first line is a header.
  • Fields are separated by commas, and each record should contain the same number of fields.
  • A field that contains a comma, a double quote or a line break should be enclosed in double quotes.
  • A double quote inside a quoted field is escaped by doubling it.
  • Spaces are part of the field value; they are not automatically trimmed.
  • The last record may or may not end with a line break.

The example below follows those rules. It contains three records with three fields each:

id,name,note
1,"Smith, Jane","She said ""hi"""
2,Lee,"Line one
line two"

Parsed correctly, the first data record holds 1, Smith, Jane (one field, comma included) and She said "hi". The second holds 2, Lee, and a note that spans two physical lines. That last point matters: a CSV record is not always one line of text, so splitting a file on line breaks or on every comma corrupts quoted fields.

Dialect rules: what varies between files

A dialect is the combination of choices a producer made. The main parameters are:

Parameter | Common variants | What goes wrong if misread
Delimiter | comma, semicolon, tab, pipe, colon | Fields merge into one column or split in the wrong places
Quote character | double quote, single quote, none | Embedded delimiters break records apart
Escape style | doubled quote, backslash, none | Quotes inside values end fields early or leave stray characters
Line ending | CRLF, LF | Extra blank rows or stray carriage-return characters at line ends
Header | present or absent | Column names treated as data, or the first data row lost as a header
Character encoding | UTF-8, UTF-8 with a byte order mark, legacy single-byte encodings | Accented letters and symbols turn into garbled characters
Decimal and date conventions | 3.50 vs 3,50; day-first vs month-first dates | Numbers and dates silently change meaning

Semicolon-delimited files are common where the comma serves as the decimal separator, because some spreadsheet applications choose the delimiter from the system's regional list separator. In this example the semicolon separates fields, so neither comma needs quoting:

id;name;amount
1;Smith, Jane;3,50

Read with a semicolon delimiter, this yields 1, Smith, Jane and 3,50. Read as comma-delimited, the same line becomes three different fields (1;Smith, Jane;3 and 50) and the header becomes a single field. Both readings are structurally valid, which is why the dialect has to be known or detected rather than assumed.

Not every delimited format uses quoting. Some Unix-style DSV files escape a delimiter with a backslash instead, and many tab-separated files simply forbid tabs and line breaks inside values. A converter that assumes CSV-style quoting can misread these files in either direction.

What a dialect conversion actually changes

Converting between dialects, for example from semicolon-separated to comma-separated, changes the stored characters in the file: the delimiter, the quoting around fields that now need it, and possibly the line endings and encoding. If the converter parses the source correctly and writes valid output, the field values themselves are unchanged. The risk lies entirely in the parsing step: a wrong delimiter or quote assumption bakes the error into the new file.

Opening a CSV in a spreadsheet is a different kind of change. The spreadsheet shows a presentation of the data and often interprets values as it loads them: stripping leading zeros from codes such as 00742, turning long digit strings into rounded or scientific notation, or reading 03/04 as a date. If you then save from the spreadsheet, those interpretations become stored changes. Viewing alone does not alter the file; saving after an interpreted import can.

Some tools describe this work as reformatting or cleaning. It helps to ask which of three things a given step does: re-delimit the same values, re-encode the characters, or reinterpret the values as typed data. Only the first two are meaning-preserving by design.

How dialect detection works and where it fails

Automatic dialect detection, sometimes called sniffing, typically examines a sample of the file and looks for a candidate delimiter that appears a consistent number of times per line, along with signs of a quote character. Python's standard csv module, for example, documents a Sniffer class that guesses the delimiter and quoting from a sample and offers a separate heuristic for whether the first row is a header. These are documented as guesses, not guarantees.

Detection struggles when the evidence is ambiguous. Consider a one-column file of comments that was written without quoting:

comment
Great, fast service
Slow, but friendly

The intended structure is one column. A detector may pick the comma because it appears once in each data line, producing a two-column table under a one-column header. Other failure-prone cases include very small samples, files where the delimiter character also appears in unquoted values, mixed line endings, and files whose first lines differ from the rest (such as export notes above the header).

Practical checks after detection: confirm that every record has the same field count, that known values with embedded commas or quotes come through whole, that accented characters display correctly, and that the header guess matches what you know about the file. When the producer documents its dialect, specifying it explicitly is more reliable than detection.

Will the result remain readable and usable after copying or sharing?

Because CSV is plain text, it copies and pastes without losing characters as long as the encoding is preserved. Usability depends on what the receiving side does with it:

  • Copying a range of cells out of a spreadsheet commonly places tab-separated text on the clipboard rather than comma-separated text, so pasted data may arrive in a different dialect than the file it came from.
  • Pasting raw CSV into a chat, email or document shows delimiters and quotes as literal characters; the table structure is only visible to software that parses it.
  • A file without a declared encoding may be read with the wrong one; a UTF-8 byte order mark helps some applications and appears as stray characters in others.
  • Cells that begin with characters such as =, +, - or @ may be treated as formulas when opened in a spreadsheet, a risk known as CSV or formula injection. Files from untrusted sources deserve caution before opening them in a spreadsheet.
  • Searching raw CSV text works for literal values, but a search will not know which column a match belongs to.

For accessibility, raw CSV is a poor reading format. A screen reader presented with the text will generally encounter it as a stream of values and punctuation, with no table semantics linking each value to its column header. Opened in an application that renders it as a proper table, the same data can be navigated by row and column. This review has not tested specific screen readers or destinations, so any claim about a particular product should be checked against its documentation or a direct test.

When people rather than programs need to read the content, share a rendered table, a short plain-text summary or a document with real table markup alongside or instead of the raw file.

Is a CSV dialect conversion suitable for your use?

Converting or normalizing a delimited file to a consistent dialect is a sound choice when the goal is moving tabular data between programs. Its main benefit is predictability: one delimiter, standard quoting, a known encoding and one line-ending style make the file easier for downstream tools to parse. The decisive tradeoff is that the conversion is only as accurate as the initial parse; a misdetected delimiter or encoding produces a clean-looking file with wrong data in it.

  • Suitable: exchanging data between systems, importing into databases or scripts, archiving tabular data in an open format, normalizing exports from several sources.
  • Use with care: data containing leading zeros, long identifiers, dates or decimal commas, where any spreadsheet step can reinterpret values; files from unknown producers where the dialect must be guessed.
  • Prefer another format: data with nested structures or multiple value types per field, where a structured format such as JSON fits better; data intended mainly for human reading, where a rendered table or plain-text summary is clearer and more accessible.

Plain prose or a simple formatted table is preferable when the audience is people reading on screen or with assistive technology, when only a few values need to be communicated, or when the recipient's software and locale are unknown and a misread delimiter would cause confusion.

Evidence gaps

This overview relies on the published CSV description and general, verifiable parsing principles. No specific detection tool, converter, spreadsheet version or assistive technology was tested for it, and no accuracy rates for dialect detection are claimed. Behavior of any named tool, including how it handles encodings, byte order marks, headers and type conversion, should be confirmed from its own documentation or a scoped test with representative files.