Non-printable ASCII characters list
By Flavio
Published · Updated
Tagged: Computer
A reference table of all the non-printable ASCII characters, listing their decimal and hexadecimal codes alongside names like NULL, BEL, TAB, and ESC.
Non-printable ASCII characters are the control codes. They sit outside the printable range (decimal 32 to 126). That means codes 0 to 31, plus DEL at 127.
Here is the full list:
| Dec | Hex | Abbr | Name | Caret | Escape |
|---|---|---|---|---|---|
| 0 | 00 | NUL | Null | ^@ | \0 |
| 1 | 01 | SOH | Start of Heading | ^A | |
| 2 | 02 | STX | Start of Text | ^B | |
| 3 | 03 | ETX | End of Text | ^C | |
| 4 | 04 | EOT | End of Transmission | ^D | |
| 5 | 05 | ENQ | Enquiry | ^E | |
| 6 | 06 | ACK | Acknowledge | ^F | |
| 7 | 07 | BEL | Bell | ^G | \a |
| 8 | 08 | BS | Backspace | ^H | \b |
| 9 | 09 | HT | Horizontal Tab | ^I | \t |
| 10 | 0A | LF | Line Feed | ^J | \n |
| 11 | 0B | VT | Vertical Tab | ^K | \v |
| 12 | 0C | FF | Form Feed | ^L | \f |
| 13 | 0D | CR | Carriage Return | ^M | \r |
| 14 | 0E | SO | Shift Out | ^N | |
| 15 | 0F | SI | Shift In | ^O | |
| 16 | 10 | DLE | Data Link Escape | ^P | |
| 17 | 11 | DC1 | Device Control 1 (XON) | ^Q | |
| 18 | 12 | DC2 | Device Control 2 | ^R | |
| 19 | 13 | DC3 | Device Control 3 (XOFF) | ^S | |
| 20 | 14 | DC4 | Device Control 4 | ^T | |
| 21 | 15 | NAK | Negative Acknowledge | ^U | |
| 22 | 16 | SYN | Synchronous Idle | ^V | |
| 23 | 17 | ETB | End of Transmission Block | ^W | |
| 24 | 18 | CAN | Cancel | ^X | |
| 25 | 19 | EM | End of Medium | ^Y | |
| 26 | 1A | SUB | Substitute | ^Z | |
| 27 | 1B | ESC | Escape | ^[ | \e (not standard C) |
| 28 | 1C | FS | File Separator | ^\ | |
| 29 | 1D | GS | Group Separator | ^] | |
| 30 | 1E | RS | Record Separator | ^^ | |
| 31 | 1F | US | Unit Separator | ^_ | |
| 127 | 7F | DEL | Delete | ^? |
The caret column is how terminals and tools like cat -v show the character. ^G means “Ctrl+G”, and on a terminal pressing Ctrl+G sends code 7.
The escape column is the backslash sequence C uses to write the character, and many other languages copied them. Support varies, though. JavaScript has no \a or \e (it reads them as plain a and e), and Python has no \e. Hex escapes work everywhere: \x07 for BEL, \x1b for ESC.
Which ones you’ll actually meet
Most of these codes were made for teletypes and old serial lines. Today you’ll mostly run into these:
- TAB (9), LF (10) and CR (13): tabs and line endings. Unix and macOS end lines with
\n. Windows ends them with\r\n. A stray\ris why a script copied from Windows can fail on Linux with weird errors. - ESC (27): starts the escape sequences that terminals use for colors and cursor movement.
\x1b[31mturns the text red. - NUL (0): ends strings in C, and shows up in binary files.
- BEL (7): makes the terminal beep or flash.
- DEL (127): the Backspace key on many terminals sends this, not BS.
Ctrl+C (ETX) and Ctrl+D (EOT) still do things in a terminal too. Ctrl+C interrupts the running program, and Ctrl+D on an empty line means “end of input”. In many terminals Ctrl+S (XOFF) also freezes the output until you press Ctrl+Q (XON).
See them in a file
Most editors don’t show these characters at all, so a file can look fine and still break a parser.
cat -v prints them in caret notation:
printf 'hello\tworld\r\nbell\a here\n' > test.txt
cat -v test.txt
hello world^M
bell^G here
Use cat -vet to also show tabs as ^I and the end of each line as $. That’s an easy way to spot Windows line endings:
hello^Iworld^M$
bell^G here$
To see the raw bytes, use hexdump -C or od -c:
od -c test.txt
Find and remove them
grep can list the lines that contain a control character. Set LC_ALL=C so it works on raw bytes:
LC_ALL=C grep -n '[[:cntrl:]]' test.txt
[[:cntrl:]] matches tabs too. To skip tabs and newlines and only find the unusual ones:
LC_ALL=C grep -n "$(printf '[\001-\010\013-\037\177]')" test.txt
If the file contains a NUL byte, grep may only print Binary file test.txt matches. Add -a to treat it as text.
To delete them and keep tabs and newlines, use tr:
LC_ALL=C tr -d '\000-\010\013-\037\177' < input.txt > clean.txt
That also removes \r, so it turns Windows line endings into Unix ones.
In JavaScript, the same thing is a regular expression:
const clean = text.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, '')
And to check whether a string has any control character at all:
/[\x00-\x1F\x7F]/.test('a\tb') // true
In Python, str.isprintable() returns False if the string contains one of them:
'a\x07b'.isprintable() # False
What about 128 to 159?
ASCII stops at 127. Codes 128 to 159 are a second set of control codes called C1, defined later outside ASCII. You’ll see them in Latin-1 and Unicode, but they’re not ASCII characters.
For the characters you can type and print, see the printable ASCII characters list.
Want me to talk about your product? You can sponsor this site.
Related posts about computers: