Home / Guides

Carriage Return and Line Feed: CR, LF and CRLF vs LF Explained

Published 2026-10-14

Every line of text ends with a marker that you never see. On Windows that marker is two characters, a carriage return followed by a line feed. On macOS and Linux it is the line feed alone. Most of the time nobody notices, until a script will not run or every line of a file shows up as changed. This guide explains CR, LF and CRLF, where they came from, and how to see and convert them.

CR, LF and CRLF in one table

NameShort formUnicodeDecimalHexEscapeCaret form
Carriage returnCRU+000D130D\r^M
Line feedLFU+000A100A\n^J
Both in a rowCRLFU+000D U+000A13 100D 0A\r\n^M^J

Both are control characters: they have no shape of their own and exist to tell a device what to do. The line feed is often called a newline, and that is the meaning of \n in most programming languages.

Where the two characters come from

The names describe a typewriter. The carriage was the part that held the paper and slid sideways as you typed. A carriage return pushed it back so that typing started again at the left margin, and a line feed rolled the paper up by one line. A typist did both with a single lever.

Teleprinters, the machines that printed text sent over a wire, needed a separate code for each movement. Early computers used teleprinters as their terminals, so both codes ended up in the ASCII character set and in every file those computers wrote. The Enter key on some keyboards is still labelled Return for the same reason.

Later systems disagreed on how many of the two codes were really needed to end a line in a file, and the disagreement never went away.

Which systems use which

Line endingUsed by
LFLinux, macOS, Android, iOS, and Unix systems in general
CRLFWindows and, before it, MS-DOS; also network protocols such as HTTP headers and email, and the usual definition of the CSV format
CRThe classic Mac OS, up to version 9; rare today

Modern programs cope with either style when they read a file. Notepad on Windows used to show a file with LF endings as one endless line, but it has handled all three styles since an update to Windows 10 in 2018. The trouble today is mostly with tools that are strict about what they accept.

Symptoms of wrong or mixed line endings

How to see which line endings a file has

file notes.txt
od -c notes.txt | head

In the dump, a carriage return appears as \r and a line feed as \n.

How to convert between CRLF and LF

In an editor

In Visual Studio Code, click the LF or CRLF label in the status bar, choose the other one and save. In Notepad++, use Edit > EOL Conversion. In Vim, type :set ff=unix or :set ff=dos and then write the file.

On the command line

The dos2unix and unix2dos utilities exist for exactly this purpose, although you may have to install them. Without them, this removes every carriage return from a file:

tr -d '\r' < input.txt > output.txt

Perl can edit a file in place, turning CRLF into LF:

perl -pi -e 's/\r\n/\n/' notes.txt

In Git

Git can keep LF endings in the repository and convert them on each computer. The setting core.autocrlf controls this per machine. A .gitattributes file in the repository is more dependable, because it travels with the project and applies to everyone:

* text=auto
*.sh text eol=lf
*.bat text eol=crlf

The first line lets Git normalise text files. The other two force a particular ending for files that need one.

In an editor configuration

Many editors read a file named .editorconfig. The line end_of_line = lf in it tells them which ending to write for new files.

In a spreadsheet

A line break inside a cell is a line feed, character 10. To remove a stray carriage return from a cell:

=SUBSTITUTE(A1, CHAR(13), "")

Line endings in the AI Text Cleaner

When you paste text into the AI Text Cleaner, every CRLF pair and every lone carriage return becomes a single line feed. This is not an option you can switch off, and the tool has no setting for producing CRLF. The cleaned text always uses LF, which is what web forms, code editors and most online tools expect. Line endings are not shown in its list of unusual characters, because every text has them.

Rarer line-break controls are treated as control codes: with Remove invisible characters on, the vertical tab, the form feed and the next-line character U+0085 are deleted and reported in the list. If your goal is to get rid of the line breaks themselves, see how to remove line breaks.

Other characters that end a line

CR and LF are not the only ones. Unicode also defines the line separator U+2028 and the paragraph separator U+2029, and the control set includes the vertical tab U+000B, the form feed U+000C and the next-line character U+0085. They are uncommon, but when one slips into a data file, some programs treat it as a line break and others do not, which produces rows that split in one tool and not in another.

Quick answers

What is the difference between a carriage return and a line feed? They are two different control characters, numbers 13 and 10. Originally the first moved to the start of the line and the second moved down one line. Today one or both of them mark the end of a line, depending on the system.

Should I use CRLF or LF? Use LF for code, scripts and anything shared between systems, and let tools convert where needed. Keep CRLF for files that require it, such as Windows batch files.

What does ^M mean at the end of a line? It is the way many Unix tools display a carriage return. It tells you the file has Windows line endings, or a mixture.

Try it on your own text. Paste text with mixed line endings and copy it back with plain line feeds. Open the AI Text Cleaner

Related guides