What is CRLF vs LF (Line Endings)?

CRLF and LF are the two conventions for marking the end of a line in text files, differing between Windows and Unix systems.

CRLF and LF refer to the invisible characters that mark the end of a line in a text file. LF (Line Feed, character U+000A, written \n) is the Unix, Linux, and macOS convention, using a single character. CRLF (Carriage Return plus Line Feed, \r\n) is the Windows convention, using two characters. These historical differences trace back to typewriters and early teletype machines.

The distinction is normally invisible but becomes very real when files move between operating systems. A file created on Windows opened in an older Unix tool may show stray carriage-return characters, while a Unix file opened in basic Windows editors may display as one long line with no breaks. Modern editors handle both, but scripts, parsers, and diff tools can behave unexpectedly when line endings are mixed.

Line endings frequently cause headaches in version control and collaboration. A commit that changes every line ending from LF to CRLF creates a massive, meaningless diff that obscures real changes. This is why tools like Git offer settings to normalize line endings, and why teams standardize on one convention - usually LF - through configuration files to keep repositories clean.

Line endings also matter in data processing. Some protocols and formats explicitly require CRLF - HTTP headers and the SMTP email protocol, for example - while many programming tools default to LF. When parsing CSV or log files, inconsistent or unexpected line endings can create phantom blank lines or fields with trailing carriage returns, so normalizing them is a common cleanup step before processing.

Examples

  • LF (\n): Unix, Linux, and macOS line endings
  • CRLF (\r\n): Windows line endings, also required by HTTP and SMTP
  • A CSV from Windows leaving a trailing \r on the last field of each row

Common questions

Which line ending should I use?
LF is the modern cross-platform default and is preferred in most codebases and version control. Use CRLF only where a protocol or format requires it, such as HTTP headers or certain Windows-specific tools.
Why does my file look like one long line?
You are likely viewing a file with LF endings in an editor that only recognizes CRLF, or vice versa. Modern editors detect both; older or basic ones may not render the other convention's breaks.
How do I stop line endings from cluttering Git diffs?
Standardize on one convention and configure Git to normalize line endings (for example via a .gitattributes file). This prevents commits that change every line's ending from generating huge, meaningless diffs.

Related tools

Related terms for CRLF vs LF (Line Endings)