Count CSV Rows
Count the number of rows in a CSV file instantly. Handles quoted fields, multi-line values, various delimiters, and large files with RFC 4180 compliance.
Drop your CSV file here
or click to browse · .csv .tsv .txt
Preview (first 5 rows)
About
Counting rows in a CSV file is not equivalent to counting newline characters. A conformant CSV per RFC 4180 permits quoted fields containing embedded newlines, meaning a single logical row can span multiple physical lines. Naive line-counting tools (wc -l, text editor line numbers) will overcount in these cases, producing incorrect data inventories. This matters when validating ETL pipelines, checking data exports against source record counts, or estimating processing time for batch operations where the row count drives resource allocation.
This tool implements a state-machine parser that tracks whether the cursor is inside a quoted field, correctly distinguishing data newlines from row-terminating newlines. It auto-detects the delimiter (comma, semicolon, tab, pipe) by frequency analysis of the first 5 lines, strips BOM prefixes, and excludes trailing empty lines. For files exceeding 1 MB, parsing is offloaded to a Web Worker to keep the interface responsive. Limitation: this tool assumes UTF-8 or ASCII encoding. Files in UTF-16 or legacy encodings (Shift-JIS, Windows-1252) may produce incorrect counts if they contain multi-byte sequences that alias delimiter or quote characters.
Formulas
The row counting algorithm uses a finite state machine with two states: UNQUOTED and QUOTED. The transition rules determine whether a newline character increments the row counter R.
For each character c in input:
After full traversal, if the file does not end with a newline and the last row contains data, R is incremented by 1. The total data row count is then R − 1 if the header toggle is enabled, otherwise R.
Delimiter auto-detection scores each candidate delimiter d by computing the standard deviation σ of occurrence counts across the first 5 lines. The delimiter with the lowest non-zero σ and highest mean count wins, as consistent frequency implies structural use rather than incidental appearance in data.
Reference Data
| Delimiter | Common Name | Symbol | File Extension | Auto-Detected | Notes |
|---|---|---|---|---|---|
| Comma | CSV | , | .csv | Yes | RFC 4180 standard |
| Semicolon | CSV (European) | ; | .csv | Yes | Common when locale uses comma as decimal separator |
| Tab | TSV | \t | .tsv, .tab | Yes | Rarely appears inside field values |
| Pipe | PSV | | | .psv, .txt | Yes | Used in medical (HL7) and financial data |
| Caret | Caret-SV | ^ | .txt | No | Rare; use manual override |
| Tilde | Tilde-SV | ~ | .txt | No | Legacy mainframe exports |
| RFC 4180 Key Rules | |||||
| Rule 1 | Each record is on a separate line, delimited by a line break (CRLF) | ||||
| Rule 2 | Last record may or may not have an ending line break | ||||
| Rule 3 | Optional header line with same format as records | ||||
| Rule 4 | Fields may be enclosed in double quotes | ||||
| Rule 5 | Fields containing line breaks, double quotes, or commas must be quoted | ||||
| Rule 6 | Double quote inside a quoted field is escaped as "" | ||||
| Common Row Count Discrepancies | |||||
| Cause | Effect on naive count | This tool | |||
| Quoted newlines | Overcounts | Correct | |||
| Trailing empty line | +1 phantom row | Excluded | |||
| BOM prefix | First field corrupted | Stripped | |||
| Mixed line endings (CR/LF/CRLF) | Undercounts or overcounts | Normalized | |||