ASCII Cheat Sheet
ASCII reference: printable characters, control codes, and decimal/hex/octal values.
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.
| Fact | Value |
|---|---|
| Width | 7 bits. |
| Total code points | 128. |
| Printable range | Decimal 32–126. |
| Control range | Decimal 0–31 plus 127. |
| UTF-8 relationship | ASCII bytes are valid UTF-8 with the same values. |
| Case difference | Uppercase 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.
| Dec | Hex | Name | Common notation |
|---|---|---|---|
| 0 | 00 | NUL | \\0 |
| 7 | 07 | BEL | \\a |
| 8 | 08 | Backspace | \\b |
| 9 | 09 | Horizontal tab | \\t |
| 10 | 0A | Line feed | \\n |
| 13 | 0D | Carriage return | \\r |
| 27 | 1B | Escape | ESC |
| 32 | 20 | Space | |
| 127 | 7F | Delete | DEL |
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.
| Range | Decimal | Hex | Characters |
|---|---|---|---|
| Digits | 48–57 | 30–39 | 0–9 |
| Uppercase | 65–90 | 41–5A | A–Z |
| Lowercase | 97–122 | 61–7A | a–z |
'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.
| Decimal range | Hex range | Characters |
|---|---|---|
| 32–47 | 20–2F | Space, ! through / |
| 48–57 | 30–39 | Digits 0–9 |
| 58–64 | 3A–40 | : through @ |
| 65–90 | 41–5A | Uppercase A–Z |
| 91–96 | 5B–60 | [ through ` |
| 97–122 | 61–7A | Lowercase a–z |
| 123–126 | 7B–7E | { through ~ |
Conversion examples
Decimal, hexadecimal, and octal are different representations of the same numeric code point. Prefixes and formatting conventions vary by language.
printf '%d\n' "'A"
printf '%02X\n' "'A"
printf '%03o\n' "'A"
for character in "Az09":
code = ord(character)
print(character, code, hex(code), oct(code))
| Character | Decimal | Hex | Octal |
|---|---|---|---|
| Space | 32 | 20 | 040 |
0 | 48 | 30 | 060 |
A | 65 | 41 | 101 |
a | 97 | 61 | 141 |
~ | 126 | 7E | 176 |
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.
text = "ASCII + café"
encoded = text.encode("utf-8")
print(encoded)
print(encoded.decode("utf-8"))