Line Break ASCII Code: CR, LF and What the Enter Key Actually Produces

The ASCII codes for line breaks are LF (10, 0x0A) and CR (13, 0x0D). Learn how Enter maps to them, how CRLF differs from LF, and when conversion is safe.

ASCII has two control characters for line breaks: Line Feed (LF), code 10, and Carriage Return (CR), code 13. Systems combine them in different ways, so a "new line" can be stored as LF, as CR, or as the two-character pair CR LF. Pressing Enter does not settle which one you get. That depends on the program receiving the key. This guide covers the codes, what converting between conventions changes in the stored text, and when a conversion is safe.

The two codes at a glance

Name | Abbreviation | Decimal | Hex | Common escape | Caret notation | Unicode code point
Line Feed | LF | 10 | 0x0A | \n | ^J | U+000A
Carriage Return | CR | 13 | 0x0D | \r | ^M | U+000D

The names come from teleprinters. Carriage return moved the print head back to the start of the line, and line feed advanced the paper by one line. Early devices needed both actions, which is why the CR LF pair still exists.

Which systems use which line ending

  • LF alone: Linux, other Unix-like systems, and macOS since Mac OS X.
  • CR LF: Windows text files, plus many internet protocols that define CR LF as the line terminator in their headers and commands, including HTTP and SMTP.
  • CR alone: classic Mac OS before Mac OS X. You mostly see it today in old files.

Unicode adds other line-breaking characters, including NEXT LINE (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029). They are outside ASCII and rarely appear in ordinary files. They can still matter if you are inspecting text that came from word processors or certain data feeds.

What ASCII code does Enter send?

Enter is a key, not a character, so the answer depends on context. On Windows, the virtual key code for Enter is 0x0D (13), the same value as CR. In browsers, the legacy keyCode property also reports 13, while the current event.key property reports the string "Enter". In a Unix terminal, Enter normally sends CR (13). The terminal driver usually translates that to LF (10) before the program reads it, which is why programs on those systems see \n. Text editors then insert whatever line ending they are configured for: CR LF in many Windows editors and LF on most other platforms. If you need to know what Enter produced in a particular file, inspect the saved bytes rather than relying on the keystroke.

What a line-ending conversion actually changes

Converting between LF and CR LF changes the stored characters. It is not a visual effect. A CR LF to LF conversion deletes one byte per line, and the reverse conversion adds one. Most editors show the visible text identically either way. Software that compares bytes sees a different file: checksums, digital signatures, diff tools and strict parsers all register the change.

Text: hello, line break, world

With CR LF (Windows convention):
68 65 6C 6C 6F 0D 0A 77 6F 72 6C 64
 h  e  l  l  o CR LF  w  o  r  l  d

With LF only (Unix/macOS convention):
68 65 6C 6C 6F 0A 77 6F 72 6C 64
 h  e  l  l  o LF  w  o  r  l  d

This differs from the transformations often grouped with it in text tools. Mirrored or flipped text either swaps characters for look-alike Unicode glyphs or applies a visual effect such as a CSS transform. Bidirectional display changes the order in which characters are shown without changing the order in which they are stored. Line-ending conversion does neither of these things. It only replaces control characters, and nothing visible changes.

A caution for reverse-text tools

Tools that reverse text character by character can break line endings. If the input contains CR LF, a naive reversal produces LF CR. That is not a valid Windows line ending, and some programs will display it as an extra blank line or a stray symbol. A safer approach is to split the text into lines first, reverse each line or the order of lines, and then rejoin them with the intended line ending. The same principle applies to other multi-code-point units. Accented letters built from combining marks, and emoji made of several code points, should be reversed as whole units rather than code point by code point. Check a reversal tool's output on a sample containing CR LF before trusting it with real text.

How to check which line ending a file uses

# Show control characters (CR appears as \r)
od -c file.txt | head

# Hex view (look for 0d 0a or a lone 0a)
xxd file.txt | head

# Report the line terminators
file file.txt

# Python: confirm the code values
python3 -c "print(ord('\n'), ord('\r'))"   # prints: 10 13

To convert between the two conventions, use the dos2unix and unix2dos utilities, or the line-ending setting in an editor. In Git repositories, the core.autocrlf setting and the .gitattributes file control whether line endings are converted on checkout and commit. Set them deliberately so the repository does not fill with whole-file diffs caused only by line endings.

Will line breaks survive copying and sharing?

Often, but you should not assume they will survive unchanged. Clipboards, browsers and messaging apps may normalize line endings when text passes through them. The HTML specification is one documented example: a textarea's value is exposed to scripts with LF line breaks, and form submission normalizes them to CR LF. Other destinations, such as specific chat apps, email clients or content management systems, have their own behavior. No scoped tests of particular destinations were available for this article, so check the actual bytes after pasting whenever exact line endings matter.

Screen readers generally treat line breaks as structure rather than reading them aloud as characters. This article does not cover how a lone CR or a malformed LF CR sequence is handled by any specific assistive technology. If accessibility matters for your output, test it with the screen reader your audience uses. Search tools and editors usually treat LF and CR LF as equivalent line breaks. A stray CR, however, can show up as a visible ^M or as a hidden character that causes search terms or comparisons to fail to match.

Is a line-ending conversion right for your use?

Converting to the target platform's convention is usually the right choice. The main benefit is compatibility. Shell scripts with CR LF endings can fail on Unix-like systems, and some older Windows tools display LF-only files as one long line. Network protocols that require CR LF need it exactly. The tradeoff is that conversion changes the bytes, which breaks checksums and signatures and can create noisy diffs in version control.

Leave the file in its original form when byte-for-byte fidelity matters: signed documents, files verified by hash, or data whose format specification defines the line ending. In those cases, inspect the file and keep its existing line endings rather than converting. For ordinary sharing, plain text with your platform's default line ending is the safest choice. Avoid running text through reversal or styling tools that may alter control characters unless you have checked their output first.