What does the backslash really escape?

It's used as an escaping character. But I always wonder what's escaping, or what's being escaped from.

I know "\n" designates a new line. But what where does the escaping come in? Why is it called that?

  • 15
    It is escaping my wrath when it screws up my strings. Oct 6, 2011 at 11:34

4 Answers 4


The backslash is used as a marker character to tell the compiler/interpreter that the next character has some special meaning. What that next character means is up to the implementation. For example C-style languages use \n to mean newline and \t to mean tab.

The use of the word "escape" really means to temporarily escape out of parsing the text and into a another mode where the subsequent character is treated differently.

  • 8
    Depending on the character, a backslash may be telling the compiler/interpreter that the following character has no special meaning. For instance, when escaping quotation marks.
    – Ryan Kinal
    Oct 6, 2011 at 13:04
  • 12
    Or escaping itself.
    – Malfist
    Oct 6, 2011 at 14:44


It is a term related to that of an escape sequence and an Esc (escape) key.

The character itself isn't "running away" from any other character. One might say the character following the escape character (say, \n from your example) escapes the fate of being used as an ordinary n in some application, and is used instead as a newline.

  • This answer helped me best to understand, here are some examples in bash that helped me see it in action: echo "$(echo "upg")" => upg echo '$(echo "upg")' => $(echo "upg") echo "\$(echo "upg")" => $(echo upg) echo "\$(echo "upg")" => $(echo upg) echo "\$(echo \"upg\")" => $(echo "upg")
    – deepGrave
    Dec 30, 2022 at 16:43

Escape sequences have a lot in common with the concept of out-of-band communication:

Also sometimes used to describe what communications people call shift characters, such as the ESC that leads control sequences for many terminals, or the level shift indicators in the old 5-bit Baudot codes.

Let's say you're doing a file transfer over a serial port and you negotiate with the computer on the other end: "OK, here comes the file". Since in the general case all characters might be valid file characters (if it's an ASCII file) you have some problems:

  • How do you know where the end of the stream is?
  • Some schemes use ASCII NUL (zero) to terminate, like strings in some languages, but then you can't have that character in the file. That's not allowable in some settings, like file transfers. Zero could be a valid character.
  • You could send the expected file length first, but what if you need to abort?

Various people throughout the history of computing have implemented lots of different methods to get around this problem.

In the case of literal strings in a programming language, it's a similar problem. The first quote says "here comes the string - start reading until you get another quote". Of course, then you have the problem of sending a quote character, so they invented the slash escape sequence. If you see a slash and then a quote, then that's a literal quote, not the end of the string. Unfortunately you just swallowed a spider to eat a fly, because now you can't send the literal slash-quote combination. So, you can escape a slash with another slash. So slash-slash means slash, slash-quote means quote. That allowed them to use slash for other unprintable or hard-to-print characters like carriage returns, line feeds, tabs, etc.


It's an escape from the parsing context, that is demanding (what a villain) n to be interpreted as n instead of as a newline.

The most interesting distinction about it is that an escape doesn't switch parsing context the way a quote character " (or many other symbols) would do , requiring another " (or some other symbol) to get back to the former context. They just take a little diversion but get back on the road ASAP.

Yet no one talks anymore about parsing contexts, as much as no one seems to write parsers anymore, since the advent of xml and json. Some problems stop being mainstream, go into a niche and weird niche concepts like that remain lingering around.

Not the answer you're looking for? Browse other questions tagged or ask your own question.