Non-printable ASCII characters list

By

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:

DecHexAbbrNameCaretEscape
000NULNull^@\0
101SOHStart of Heading^A
202STXStart of Text^B
303ETXEnd of Text^C
404EOTEnd of Transmission^D
505ENQEnquiry^E
606ACKAcknowledge^F
707BELBell^G\a
808BSBackspace^H\b
909HTHorizontal Tab^I\t
100ALFLine Feed^J\n
110BVTVertical Tab^K\v
120CFFForm Feed^L\f
130DCRCarriage Return^M\r
140ESOShift Out^N
150FSIShift In^O
1610DLEData Link Escape^P
1711DC1Device Control 1 (XON)^Q
1812DC2Device Control 2^R
1913DC3Device Control 3 (XOFF)^S
2014DC4Device Control 4^T
2115NAKNegative Acknowledge^U
2216SYNSynchronous Idle^V
2317ETBEnd of Transmission Block^W
2418CANCancel^X
2519EMEnd of Medium^Y
261ASUBSubstitute^Z
271BESCEscape^[\e (not standard C)
281CFSFile Separator^\
291DGSGroup Separator^]
301ERSRecord Separator^^
311FUSUnit Separator^_
1277FDELDelete^?

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:

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: