All cheat sheets

ASCII Cheat Sheet

ASCII reference: printable characters, control codes, and decimal/hex/octal values.

Reference
ascii
encoding

ASCII is a 7-bit character encoding with 128 code points: 33 control codes, 95 printable characters, and the space character. It remains important in protocols and source files, while UTF-8 preserves ASCII values as a compatible subset.

Key facts and ranges

ASCII values run from decimal 0 through 127. Printable characters occupy decimal 32 through 126; decimal 127 is DEL, not a printable glyph.

Table
FactValue
Width7 bits.
Total code points128.
Printable rangeDecimal 32–126.
Control rangeDecimal 0–31 plus 127.
UTF-8 relationshipASCII bytes are valid UTF-8 with the same values.
Case differenceUppercase and lowercase Latin letters differ by decimal 32.

Control codes

Control codes originally supported terminals and communication devices. Their names are still used in programming, logging, and protocols.

Table
DecHexNameCommon notation
000NUL\\0
707BEL\\a
808Backspace\\b
909Horizontal tab\\t
100ALine feed\\n
130DCarriage return\\r
271BEscapeESC
3220Space
1277FDeleteDEL
python
control = {"TAB": 9, "LF": 10, "CR": 13, "ESC": 27}
for name, code in control.items():
    print(name, code, f"0x{code:02X}")

Digits and letters

Digits are contiguous, as are uppercase and lowercase English letters. This makes range checks and case conversion possible in low-level code, though Unicode-aware libraries are preferable for human text.

Table
RangeDecimalHexCharacters
Digits48–5730–390–9
Uppercase65–9041–5AA–Z
Lowercase97–12261–7Aa–z
text
'A' = 65 = 0x41 = 0100 0001
'Z' = 90 = 0x5A
'a' = 97 = 0x61
'0' = 48 = 0x30

Printable punctuation

The printable area includes symbols, digits, uppercase letters, lowercase letters, and punctuation. The ranges below are compact landmarks for quick lookup.

Table
Decimal rangeHex rangeCharacters
32–4720–2FSpace, ! through /
48–5730–39Digits 0–9
58–643A–40: through @
65–9041–5AUppercase A–Z
91–965B–60[ through `
97–12261–7ALowercase a–z
123–1267B–7E{ through ~

Conversion examples

Decimal, hexadecimal, and octal are different representations of the same numeric code point. Prefixes and formatting conventions vary by language.

bash
printf '%d\n' "'A"
printf '%02X\n' "'A"
printf '%03o\n' "'A"
python
for character in "Az09":
    code = ord(character)
    print(character, code, hex(code), oct(code))
Table
CharacterDecimalHexOctal
Space3220040
04830060
A6541101
a9761141
~1267E176

ASCII and Unicode

ASCII cannot represent accented letters, most writing systems, emoji, or many symbols. UTF-8 keeps every ASCII character as a one-byte sequence and encodes other Unicode characters using additional bytes.

python
text = "ASCII + café"
encoded = text.encode("utf-8")
print(encoded)
print(encoded.decode("utf-8"))

References