If there are two keywords then they must have their own meanings. So I want to know what makes them different and what their code is.
-
2Have a look at Wikipedia: http://en.wikipedia.org/wiki/Carriage_Return#Computers – exic Oct 05 '12 at 13:54
-
5Possible duplicate of [What are carriage return, linefeed, and form feed?](http://stackoverflow.com/questions/3091524/what-are-carriage-return-linefeed-and-form-feed) – jtbandes Aug 09 '16 at 06:05
-
3Have a look at this article, It clears out everything impeccably http://digital.ni.com/public.nsf/allkb/5A5A050A3019A573862575F30061D49B – Rohit Saluja Oct 02 '16 at 08:08
-
Canonical candidate (2009): *[Difference between CR LF, LF and CR line break types?](https://stackoverflow.com/questions/1552749/difference-between-cr-lf-lf-and-cr-line-break-types)* – Peter Mortensen Feb 10 '23 at 13:13
4 Answers
A line feed means moving one line forward. The code is \n
.
A carriage return means moving the cursor to the beginning of the line. The code is \r
.
Windows editors often still use the combination of both as \r\n
in text files. Unix uses mostly only the \n
.
The separation comes from typewriter times, when you turned the wheel to move the paper to change the line and moved the carriage to restart typing on the beginning of a line. This was two steps.

- 5,870
- 1
- 20
- 22
-
29you'd think even old typewriters should have thought about making \n represent two steps. – ColacX Jul 30 '14 at 18:47
-
34@ColacX It is often useful to perform a carriage return without a line feed when overwriting the text on the current line is desired. This applies to both typewriters and terminals. – Dan Bechard Dec 29 '14 at 20:06
-
3So, in Windows, the proper sequence for the end of a line would look like `\n\r`? – Delfino Apr 07 '15 at 03:25
-
37@Delfino not really. On mechanical printers, it made sense to initiate a carriage return earlier, since it's slower, and feed the line while the carriage is still moving. – Maciej Stachowski Apr 15 '15 at 10:31
-
@Tsunamis By historical reasons, the right combination is new line and return: you push the typewriter's lever and the line will feed, pushing all way will perform carriage return. See: http://www.machinesoflovinggrace.com/manuals/Manual-RemingtonNoiseless8-9.jpg – Gustavo Apr 24 '17 at 23:03
-
-
Then why is that that in Notepad++ I can delete all \n -s, yet the CR signs remain at the ends of lines, but the whole text is not in one line, of course? Why to have two distinct characters, when you can do everything with one? – GregT Mar 23 '18 at 10:50
-
2If you would send `foo` `\r` `bar` to a terminal, you would see only _bar_ on your screen, because _foo_ will be overwritten with _bar_ after moving the cursor to the beginning of the line. The text editor obivously can't overwrite the text in the same line via control characters. So in Notepad++ a single `\r` will be interpreted similar to `\n` or `\r\n`. – Tsunamis Mar 23 '18 at 15:45
-
7
-
It's easy to remember the most commonly used order from the abbreviation CRLF - carriage return, then line feed. You'll rarely, if ever, see the order LFCR. – Mottie Sep 08 '18 at 12:17
-
Explains why the supposedly sorted list of characters I'm looking at has alternating ASCII values of 10 and 13... Was probably sorted on Windows as \r\n and is displayed on my Unix system as two separate characters. – H Froedge Nov 21 '19 at 18:15
-
1
-
1This Answer is just WRONG: `\n` is not a character - you will not find it in ASCII, ANSI, Latin-8, UTF-8 etc. It is a programing-language specific escape-sequence, originating from the language C. And it NEVER means `LF`. What it stands for is the escape-sequence representing the platforms (OS) control-character for new-line. On the contrary to that `LF` stands for linefeed - which by definition only means going down a line, not going to the start of the line. UNIX is using that symbol to do both at once, others do not. And lastly: C is not ASCII - other valid encodings lacking `LF` – ABaumstumpf Aug 02 '22 at 18:05
-
2@ABaumstumpf might it be that your comment was directed at [the answer below](https://stackoverflow.com/a/71458692/1584876) and not to this anwser? This answer does not mention _character_ or _ASCII_. – Tsunamis Jan 27 '23 at 15:03
-
@ABaumstumpf is correct. E.g., it is incorrect to say *"Windows editors often still use the combination of both as \r\n in text files"*. Lines in Windows text files end with two bytes of value 13 and 10 (usually designated by ASCII CR and LF). It does not map cleanly to \r and \n. That entirely depends on the context. For instance, in Perl, \n is by default dependent on the system it is on (CR + LF on Windows, CR on Unix, and LF on Macintosh (at least the old Macintoshes)) - the abstraction of \n can also be overridden, if necessary, by changing the definition of \n – Peter Mortensen Feb 10 '23 at 13:06
-
cont' - (variable [$/](https://perldoc.perl.org/perlvar#$/) for input and [`$\\`](https://perldoc.perl.org/perlvar#$%5C) for output). – Peter Mortensen Feb 10 '23 at 13:08
-
1Or from [a comment](https://stackoverflow.com/questions/1552749/difference-between-cr-lf-lf-and-cr-line-break-types#comment17289408_1552749): *"CR and LF are ASCII and Unicode control characters while \r and \n are abstractions used in certain programming languages."* – Peter Mortensen Feb 10 '23 at 13:09
-
(Correction: Unix uses 10 (ASCII LF) and ([old](https://en.wikipedia.org/wiki/Classic_Mac_OS)) Macintosh [uses 13](https://en.wikipedia.org/wiki/Newline#Representation) (ASCII CR).) – Peter Mortensen Feb 10 '23 at 13:33
In very layman language Enter key press is combination of carriage return and line feed.
Carriage return points the cursor to the beginning of the line horizontally and Line feed shifts the cursor to the next line vertically. Combination of both gives you the new line (\n
) effect.
Reference: https://en.wikipedia.org/wiki/Carriage_return#Computers

- 5,031
- 17
- 33
- 41

- 667
- 5
- 3
-
Also, it become the difference between breaking line and breaking paragraph when computers replaced typewriters - text processing. – Gustavo Apr 24 '17 at 22:58
-
This seems to be talking about Windows only. It's *sort of* correct for Unix-like systems, but text files only contain the newline character, `\n`, which appears as a newline + carriage return when displaying it on the screen. – wjandrea Dec 31 '20 at 03:34
Both of these are primary from the old printing days.
Carriage return is from the days of the teletype printers/old typewriters, where literally the carriage would return to the next line, and push the paper up. This is what we now call \r
.
Line feed LF
signals the end of the line, it signals that the line has ended - but doesn't move the cursor to the next line. In other words, it doesn't "return" the cursor/printer head to the next line.
For more sundry details, the mighty Wikipedia to the rescue.

- 30,738
- 21
- 105
- 131

- 169,990
- 18
- 245
- 284
-
16I believe the carriage return refers to moving to the beginning of the same line, rather than moving to the next line. The typewriter analogy refers to both moving down to the next line vertically (line feed) and returning to the beginning of the line horizontally (carriage return). http://en.wikipedia.org/wiki/Carriage_return – Feckmore Jan 17 '15 at 15:53
Both "line feed' (0x0A or 10) and 'carriage return' (0x0D or 13) are single-byte values. These values are the accepted standard for LF/CR. Most languages will type these as 'characters.' You can find these values on any standard ASCII table.
For example, in C# a string such as:
String str = "\n\r";
is two characters long (ignoring the hidden end null character '0x00' required in string types). However, you could make an equivalent array of type character such as:
char[] c = new char[](){0x0A,0x0D}; // LF, CR

- 30,738
- 21
- 105
- 131

- 23
- 4