Return Character Unicode: Code Points, ASCII Values and How to Detect Them

The return character is U+000D (ASCII 13, hex 0D, \r). Learn how it differs from line feed and CRLF, and how to detect, verify and safely convert it in text.

The return character, formally called CARRIAGE RETURN, has the Unicode code point U+000D. In ASCII it is code 13 in decimal, 0x0D in hexadecimal, and 015 in octal. Programming languages usually write it as \r, and many terminals display it as ^M. This guide explains what the character does to your text, how it relates to the line feed and to Windows-style line endings, and how to find it by its code and confirm the result without changing meaningful content.

What the return character does in text

Carriage return is an invisible control character. It is not meant to be displayed as a glyph. It signals a line break, either alone or paired with another control character. The name comes from typewriters and teleprinters, where the carriage return moved the print head back to the start of the line and a separate line feed advanced the paper. Modern software inherited both characters, and different systems combine them differently to mark the end of a line.

In practice, a carriage return in a file affects line breaks, line counts, string comparisons, regular expression matches and anything that splits text into lines. Because it is invisible, an unexpected carriage return often shows up indirectly. A value fails an equality check, a script reports a strange error on a line that looks correct, or a terminal shows a stray ^M at the end of each line.

Return character codes at a glance

Character | Unicode | Decimal | Hex | Common escape | Caret notation
Carriage return (CR) | U+000D | 13 | 0x0D | \r | ^M
Line feed (LF) | U+000A | 10 | 0x0A | \n | ^J
CR followed by LF (CRLF) | U+000D U+000A | 13 10 | 0x0D 0x0A | \r\n | ^M^J
Next line (NEL) | U+0085 | 133 | 0x85 | \x85 or \u0085 | none
Line separator (LS) | U+2028 | 8232 | 0x2028 | \u2028 | none
Paragraph separator (PS) | U+2029 | 8233 | 0x2029 | \u2029 | none

Only the first three rows are part of ASCII. NEL, the line separator and the paragraph separator are Unicode characters that some software also treats as line breaks. They are rarely the answer when someone searches for the return character code, but they matter when a text contains a break that does not match \r or \n.

Return character vs. line feed and CRLF

The carriage return is often confused with the line feed. The difference matters when you clean or convert text. The common line-ending conventions are:

  • CRLF (\r\n, bytes 0D 0A): the traditional line ending on Windows and in many internet protocols, such as HTTP headers.
  • LF (\n, byte 0A): the line ending on Linux, macOS and other Unix-like systems.
  • CR alone (\r, byte 0D): the line ending on classic Mac OS before OS X. It also appears in terminal output, where a lone CR returns the cursor to the start of the line so a progress indicator can overwrite itself.

The Enter or Return key does not insert a fixed character everywhere. The resulting line ending depends on the operating system, the application and its settings.

How the return character is encoded

In ASCII, ISO-8859-1 and UTF-8, the carriage return is stored as the single byte 0x0D. In UTF-16, it occupies two bytes, 00 0D in big-endian order or 0D 00 in little-endian order. In UTF-32, it is padded to four bytes. So when you inspect raw bytes, look for 0D in byte-oriented encodings and allow for the zero byte padding in UTF-16 and UTF-32.

Visible symbols that represent a return

Some readers want a printable symbol that stands for the return key or the carriage return, not the control character itself. These are ordinary visible characters and do not create a line break:

  • ␍ U+240D SYMBOL FOR CARRIAGE RETURN: a visible stand-in for the CR control character.
  • ⏎ U+23CE RETURN SYMBOL: commonly used to label the Return key.
  • ↵ U+21B5 DOWNWARDS ARROW WITH CORNER LEFTWARDS: another arrow often used to represent Enter or Return.

Do not substitute these symbols for U+000D in data. A file that contains ⏎ has no line break at that point.

How to find a carriage return by its code, step by step

The basic approach is the same in every tool. Make the invisible character explicit, confirm that its value is 13 (0x0D), and check whether it appears alone or directly before a line feed. The snippets below are illustrative examples of common commands. Their exact output formatting can vary by tool version and platform, so they should not be read as verified output.

Step 1: Check the file's line endings

On Linux and macOS, the file command often reports the line terminators it detects, for example by mentioning CRLF line terminators. That is a quick first signal, but confirm it at the byte level.

file notes.txt

Step 2: Make the carriage return visible

Each of the following commands reveals carriage returns in a different way. cat -A (GNU coreutils) marks CR as ^M and the end of each line as $. od -c prints CR as \r. xxd and hexdump show the raw byte 0d.

cat -A notes.txt
od -c notes.txt | head
xxd notes.txt | head

Example: for a file containing the word hi followed by a Windows line ending, the bytes are 68 69 0d 0a. A 0d directly before 0a indicates CRLF. A 0d that is not followed by 0a is a lone carriage return.

Step 3: Search for the character by code

In shells that support ANSI-C quoting, such as bash, $'\r' produces a literal carriage return that grep can match. This example counts the lines that contain one:

grep -c $'\r' notes.txt

In most regular expression engines, you can match the same character as \r, \x0D or \u000D. The available forms depend on the engine.

Step 4: Check the code inside a program

Example in Python. repr() makes invisible characters explicit, and ord() returns the numeric code:

line = "hi\r\n"
print(repr(line))                  # shows the \r and \n escapes
print([hex(ord(c)) for c in line]) # carriage return appears as 0xd
print(ord("\r") == 13)             # True

When reading files in Python, open them in binary mode or with newline="" if you need to see the original line endings. The default text mode translates line endings, so carriage returns can disappear from view.

Example in JavaScript:

const s = "hi\r\n";
for (let i = 0; i < s.length; i++) {
  if (s.charCodeAt(i) === 13) {
    console.log("carriage return at index", i);
  }
}

Step 5: Verify the result

The identification is confirmed when the character's value is 13 decimal or 0x0D, or when a byte dump shows 0d at the expected position. Note whether every 0d is followed by 0a, which indicates consistent CRLF endings, or whether some appear alone, which indicates mixed or legacy line endings.

Removing or converting return characters safely

Once you have found carriage returns, decide what they mean before you change anything. Follow these rules to avoid altering meaningful content:

  • To convert Windows line endings to Unix ones, replace the two-character sequence \r\n with \n. Do not delete every \r, because that would also remove lone carriage returns that may be intentional line breaks in classic Mac files or overwrite sequences in captured terminal output.
  • To convert legacy CR-only files, replace a lone \r with \n. Do not delete it, or adjacent lines will merge.
  • Do not run line-ending conversions on binary files such as images or archives. The byte 0x0D can appear there as ordinary data, and changing it corrupts the file.
  • Keep a copy of the original file, then re-run the inspection steps afterward to confirm that only the intended bytes changed.
  • If the file must keep CRLF, as some protocols and Windows tools expect, leave the carriage returns in place and fix the reading side instead, for example by stripping a trailing \r after splitting lines.

Example in Python, converting CRLF to LF without touching lone carriage returns:

with open("notes.txt", "rb") as f:
    data = f.read()
with open("notes_lf.txt", "wb") as f:
    f.write(data.replace(b"\r\n", b"\n"))

Dedicated utilities such as dos2unix and unix2dos also convert between conventions, and many code editors can show and change a file's line-ending setting. Behavior and default options differ between tools and versions, so check the documentation of the tool you use.

Scope and limitations

The code points, byte values and escape sequences in this guide come from the ASCII and Unicode standards and are stable. The command and code snippets are illustrative and were not run against a specific system for this article. Output formats and default options vary between tool versions, operating systems and editors, so confirm behavior in your own environment before you rely on it for bulk changes.