Identify ASCII control characters

How to spot and name ASCII control codes: what each display method changes, how results survive copying, and when a plain-text description is the safer choice.

ASCII control codes are the 33 non-printing values in the ASCII set: 0 through 31 (hex 00–1F) plus 127 (hex 7F). Instead of drawing a glyph, they tell software or hardware to do something, such as start a new line, jump to a tab stop or ring a bell. Because they are invisible, identifying one means turning it into something you can see. This review covers the common ways of doing that and whether each one keeps the text accurate and usable.

What counts as an ASCII control character

Unicode keeps the ASCII controls at the same positions, U+0000 to U+001F and U+007F, and assigns them the general category Cc (control). The space character, U+0020, is not a control even though it is invisible. It is an ordinary graphic character that takes up width.

Several look-alikes cause confusion. The C1 controls, U+0080 to U+009F, are also category Cc, but they are not part of ASCII. Unicode format characters such as the zero-width space (U+200B), the left-to-right mark (U+200E) and the right-to-left override (U+202E) are category Cf. They also hide in text, but they are not ASCII controls. An inspector that reports both the code point and the category settles which kind you have found.

Common control codes and how they are shown

Hex | Decimal | Abbreviation | Name | Caret notation | Common escape | Control Picture
00 | 0 | NUL | Null | ^@ | \0 | ␀ (U+2400)
07 | 7 | BEL | Bell | ^G | \a | ␇ (U+2407)
08 | 8 | BS | Backspace | ^H | \b | ␈ (U+2408)
09 | 9 | HT | Horizontal tab | ^I | \t | ␉ (U+2409)
0A | 10 | LF | Line feed | ^J | \n | ␊ (U+240A)
0B | 11 | VT | Vertical tab | ^K | \v | ␋ (U+240B)
0C | 12 | FF | Form feed | ^L | \f | ␌ (U+240C)
0D | 13 | CR | Carriage return | ^M | \r | ␍ (U+240D)
1B | 27 | ESC | Escape | ^[ | \x1B (\e in some languages) | ␛ (U+241B)
7F | 127 | DEL | Delete | ^? | none standard | ␡ (U+2421)

Caret notation follows a fixed rule: flip the 64 bit of the code. Tab (9) becomes 73, which is the letter I, so tab is written ^I. DEL (127) becomes 63, the question mark, so it is written ^?. Escape notation is not standardized in the same way. Which backslash sequences are recognized depends on the programming language or tool. The rarely seen codes, including the four separators FS, GS, RS and US at 1C–1F, have Control Pictures too (U+241C to U+241F).

What each identification method actually changes

The key question is whether a method only changes how the text looks or replaces the stored characters. Display-only methods are safe for inspection. Substitution methods create new text that only resembles the original.

  • Show-invisibles or whitespace display in an editor: presentation only. The stored characters are unchanged, and copying copies the real control characters.
  • Hex or code point readout: produces a separate report and leaves the original untouched. The numbers are unambiguous.
  • Caret notation (such as ^M): new text that uses two printable characters per control. It can be reversed only if you know the convention and the source never contained a literal caret followed by a letter.
  • Escape notation (such as \r\n): new text that a parser for that language can turn back into controls. It becomes ambiguous unless literal backslashes in the source are escaped too.
  • Control Pictures substitution: each control is replaced by a single printable symbol. A ␉ does not align columns and a ␊ does not break a line. Restoring the original requires a reverse mapping.
  • Stripping or removal: this is not identification. It deletes information such as line breaks and tab structure, and it is only appropriate once you have confirmed the characters are unwanted.

Terms like 'reverse', 'mirror' and 'font' need care here. Control characters have no glyph, so there is no styled, mirrored or fancy-font version of one. 'Reverse video', where some terminals show non-printing characters in inverted colors, is a display effect only. Text-reversal tools deserve a check whenever control characters are present. Reversing code points turns a CR LF line ending into LF CR, and software interprets that sequence differently.

A worked example

Take the word 'Hi', a tab, the word 'there', and a Windows-style line ending (carriage return followed by line feed). That is ten bytes:

48 69 09 74 68 65 72 65 0d 0a

The POSIX od utility with the -c option prints printable characters as themselves and controls as escapes. The offset column is in octal, so 0000012 marks the end after ten bytes:

0000000   H   i  \t   t   h   e   r   e  \r  \n
0000012

GNU cat with the -A option uses caret notation for the tab and carriage return. It marks the end of each line with a dollar sign, which is not a character in the data:

Hi^Ithere^M$

Substituting Control Pictures gives Hi␉there␍␊. That is still ten characters, but it no longer contains a tab, carriage return or line feed, so it displays on one line. Each symbol takes three bytes in UTF-8, so the encoded result is 16 bytes instead of 10.

Readability and usability after copying or sharing

Real control characters survive copying only as well as the destination allows. In general terms:
• Line endings may be normalized.
• Tabs may be converted to spaces.
• Other controls may be silently dropped.
• A NUL can cut text short in software that treats it as an end-of-string marker.
• ESC begins terminal escape sequences, so text containing it can change a terminal's display or behavior when pasted or printed. Treat unexplained ESC characters with caution.
No destination-specific tests were supplied for this review, so check how your own target application handles each control.

Substituted forms behave differently. Caret notation, escape notation and Control Pictures are ordinary printable characters, so they copy as text. Control Pictures need font support and may appear as empty boxes where a font lacks them. None of these forms will match a search for the original control character. Searching for the two characters backslash and t finds the notation, not an actual tab.

For accessibility, the raw controls are not meaningful to a listener. How screen readers announce Control Pictures symbols or caret sequences was not tested here and can vary by product and verbosity setting. In documentation, spelled-out names with code points, such as 'carriage return, U+000D', are the most dependable choice. ASCII controls do not reorder text. Visual reordering comes from Unicode bidirectional formatting characters such as U+202E, which is another reason to confirm the code point before naming a character.

Telling which character you are looking at

  • Text breaks onto a new line with nothing visible: LF, CR or CR LF. Non-ASCII separators such as U+2028 can do the same.
  • Columns misalign or a gap varies in width: likely a horizontal tab.
  • ^M at the end of lines in Unix-style tools: the file uses CR LF line endings.
  • Stray fragments like [31m or [0m: ANSI color sequences whose leading ESC was dropped or hidden.
  • A box or replacement symbol: possibly a control, possibly a character the font cannot draw. Check the code point.
  • A gap that is neither a normal space nor a tab: often a non-ASCII character such as a no-break space (U+00A0) or a zero-width character, not an ASCII control.

Useful search terms for finding a suitable tool or setting include 'show invisible characters', 'show whitespace', 'hex viewer', 'Unicode code point inspector', 'C0 control codes', 'caret notation' and 'Control Pictures block'. The od and GNU cat commands shown above are standard on many Unix-like systems. No specific online inspectors were evaluated for this review, and their data handling was not assessed, so be cautious about pasting sensitive text into them.

Verdict

Which method to use depends on the job:
• Identification: a hex or code point readout is the most reliable, because it is unambiguous and leaves the data untouched.
• Everyday editing: an editor's show-invisibles mode is the practical choice.
• Explanations and screenshots: caret notation, escape notation and Control Pictures work well, but they are substitutes. Never feed them back in as if they were the original data.
• Sharing with people or writing accessible documentation: plain text is preferable. If the destination's handling is unknown, name the character and its code point instead of embedding the control or a symbol.

Evidence gaps: this review relies on the standard ASCII and Unicode definitions and the documented behavior of the utilities named. No copy-and-paste tests for specific applications and no screen reader tests were available, so confirm behavior in the environment where the text will actually be used.