\ (Backslash) is ASCII code point 92 (0x5C), Unicode U+005C, and a printable punctuation character. It reverses the direction of the familiar forward slash — a mirror-image stroke that leans the "wrong" way, which turns out to be exactly why it became the universal escape character. In nearly every programming language and format, the backslash says "treat the next character differently." It introduces escape sequences: \n for newline, \t for tab, \\ for a literal backslash itself, and \" to embed a quote inside a string. Regular expressions pile on additional meaning — \d matches a digit, \b a word boundary — creating a layer of escaping on top of the language's own string escaping. This double duty is the source of the infamous "leaning toothpick syndrome," where a regex in a string literal requires \\\\ just to match a single literal backslash: one level of escaping for the string, another for the regex engine. Windows chose \ as its path separator (C:\Users\Documents), forever condemning developers who work across platforms to juggle / and \ in the same codebase and wonder why their path-joining logic only fails in CI. Bob Bemer added the backslash to ASCII in the early 1960s, specifically so that the two-character sequences \( and \) could represent the braces { and } on hardware that lacked them — a pragmatic invention with consequences he couldn't have foreseen. UTF-8 encodes it as a single byte 0x5C. Unicode classifies it as Po (Punctuation, Other) with the name REVERSE SOLIDUS. The visually similar set minus ∖ (U+2216) is a mathematical operator for set difference, and swapping one for the other will derail both a proof and a file path.
const char *path = "C:\\Temp\\app.log";// \\ in source becomes a single backslash at runtimeprintf("%s\n", path);// also enables escapes like \n and \t in strings
C chose \ for escape sequences in the 1970s (\n, \t, \0), and virtually every language since copied the convention. It was picked because it's rarely needed in normal text and is visually distinct from /. Now it's universal: \n (newline), \t (tab), \\ (literal backslash), \" (quote in string).
DOS 2.0 (1983) needed a path separator but / was already used for command-line switches (dir /w). Microsoft chose \. Unix had used / since 1971. This split has caused 40+ years of cross-platform headaches. Most modern Windows APIs actually accept both, but many tools still break.
To match a literal backslash in regex, you need \\. But in a string literal, each \ is already an escape, so you write '\\\\' — four backslashes to match one. This exponential escaping is called 'leaning toothpick syndrome.' Python raw strings (r'\\') and regex literals (/\\/) reduce this pain.
JSON requires \\ for a literal backslash. Windows paths like C:\Users\file must be written as C:\\Users\\file in JSON. Forward slashes work in most contexts (C:/Users/file) and don't need escaping. This is why many tools normalize paths to forward slashes regardless of OS.