When you type “Hello” and a computer stores it, what actually gets saved is a sequence of numbers: 72, 101, 108, 108, 111. That mapping between characters and numbers is ASCII — and understanding it unlocks a surprising amount of insight into how computers handle text, protocols, and data interchange.
Convert text to ASCII codes instantly →
What Is ASCII?
ASCII (American Standard Code for Information Interchange) is a character encoding standard published in 1963 by the American Standards Association. It maps 128 characters — letters, digits, punctuation, and control codes — to integers from 0 to 127, each stored in 7 bits.
The original design constraint was telegraph wire: every character needed to fit in 7 bits so transmission could be efficient. That decision from 1963 still shapes text handling in every programming language today.
ASCII covers:
- 0–31: Control characters (non-printable)
- 32–126: Printable characters (letters, digits, punctuation, space)
- 127: DEL (delete control character)
The entire ASCII character set fits in 7 bits, but computers store bytes (8 bits), leaving the 8th bit free — which is exactly how extended encodings like Latin-1 and code pages were bolted on later.
ASCII Table Highlights
Control Characters (0–31)
These are non-printable characters used to control devices and text formatting:
| Dec | Hex | Abbreviation | Meaning |
|---|---|---|---|
| 0 | 00 | NUL | Null character |
| 7 | 07 | BEL | Bell (terminal beep) |
| 8 | 08 | BS | Backspace |
| 9 | 09 | HT | Horizontal tab |
| 10 | 0A | LF | Line feed (Unix newline \n) |
| 13 | 0D | CR | Carriage return (\r) |
| 27 | 1B | ESC | Escape (ANSI terminal sequences) |
The CR+LF (\r\n) combination — decimal 13 then 10 — is the Windows line ending, a direct legacy of mechanical teletype machines where CR moved the print head to the start of the line and LF rolled the paper up one line.
Printable Characters (32–126)
32 SPACE 48 0 65 A 97 a
33 ! 49 1 66 B 98 b
34 " 50 2 67 C 99 c
...
Key values to memorize for programming:
| Character | Decimal | Hex |
|---|---|---|
| Space | 32 | 20 |
0 | 48 | 30 |
A | 65 | 41 |
a | 97 | 61 |
Z | 90 | 5A |
z | 122 | 7A |
The difference between uppercase and lowercase letters is always exactly 32 (or 0x20). This is why toggling bit 5 of an ASCII byte flips case — a trick still used in performance-sensitive parsers.
Digits 0–9 start at 48, so '5' - 48 = 5 converts an ASCII digit character to its integer value — the basis of every custom string-to-integer parser.
ASCII vs Unicode vs UTF-8
These three terms are frequently confused. Here is how they relate:
ASCII is a 7-bit encoding covering 128 characters. It was designed for English and lacks any non-Latin characters.
Unicode is a standard that assigns a unique code point to every character in every writing system — over 149,000 characters as of Unicode 15.1. Unicode itself is not an encoding; it is a character set. U+0041 is the code point for “A”. Unicode says what character each number represents, not how those numbers are stored in bytes.
UTF-8 is one way to encode Unicode code points into bytes. It is variable-width:
- Code points 0–127 (the entire ASCII range) encode as a single byte, identical to ASCII.
- Code points 128–2047 encode as 2 bytes.
- Code points 2048–65535 encode as 3 bytes.
- Code points above 65535 encode as 4 bytes.
This is the crucial insight: UTF-8 is a superset of ASCII. Any pure ASCII document is also a valid UTF-8 document. A 7-bit ASCII string will be byte-for-byte identical in UTF-8.
Other Unicode encodings:
- UTF-16: 2 or 4 bytes per character. Used internally by Windows, Java, and JavaScript’s string representation. Not ASCII-compatible.
- UTF-32: Fixed 4 bytes per character. Simple but wasteful for mostly-ASCII content.
- Latin-1 (ISO 8859-1): 8-bit extension of ASCII, adds characters 128–255 for Western European languages. Often confused with UTF-8 — they are incompatible for characters above 127.
Working with ASCII in Code
JavaScript
// Character to ASCII code
'A'.charCodeAt(0); // 65
'a'.charCodeAt(0); // 97
' '.charCodeAt(0); // 32
// ASCII code to character
String.fromCharCode(65); // 'A'
String.fromCharCode(72, 101, 108, 108, 111); // 'Hello'
// Convert string to array of ASCII codes
function toAsciiCodes(str) {
return [...str].map(c => c.charCodeAt(0));
}
toAsciiCodes('Hello'); // [72, 101, 108, 108, 111]
// Check if character is uppercase ASCII letter
function isUpperCase(char) {
const code = char.charCodeAt(0);
return code >= 65 && code <= 90;
}
// Case conversion using bit manipulation
function toggleCase(char) {
return String.fromCharCode(char.charCodeAt(0) ^ 32);
}
toggleCase('A'); // 'a'
toggleCase('a'); // 'A'
Python
# Character to ASCII code
ord('A') # 65
ord('\n') # 10
ord(' ') # 32
# ASCII code to character
chr(65) # 'A'
chr(72) # 'H'
# String to list of codes
[ord(c) for c in 'Hello'] # [72, 101, 108, 108, 111]
# Codes to string
''.join(chr(c) for c in [72, 101, 108, 108, 111]) # 'Hello'
# Check ASCII range
def is_ascii(s: str) -> bool:
return all(ord(c) < 128 for c in s)
# Python 3 built-in
'Hello'.isascii() # True
'Héllo'.isascii() # False
Go
package main
import "fmt"
func main() {
// Character to code point (rune)
r := 'A'
fmt.Println(int(r)) // 65
// Code point to character
fmt.Printf("%c\n", 65) // A
// Iterate string bytes (ASCII range)
for i, b := range []byte("Hello") {
fmt.Printf("%d: %c = %d\n", i, b, b)
}
// 0: H = 72
// 1: e = 101
// ...
// Toggle case using XOR
fmt.Printf("%c\n", 'A'^32) // a
fmt.Printf("%c\n", 'a'^32) // A
}
Practical Uses of ASCII Codes
Protocol Delimiters
Many internet protocols are ASCII-based by design. HTTP headers, SMTP commands, FTP control messages, and CSV files all use ASCII control characters or printable characters as delimiters:
- CSV uses
,(44) and\r\n(13, 10) - HTTP headers end with
\r\n\r\n(13, 10, 13, 10) - SMTP commands are plain ASCII lines terminated with
\r\n - Null-terminated strings in C use NUL (0) as the string terminator
Terminal Control Sequences
The ESC character (27, \x1b) is the basis for ANSI escape codes used to add color and cursor movement to terminal output:
# Red text in terminal
print('\x1b[31mThis is red\x1b[0m')
# Bold text
print('\x1b[1mThis is bold\x1b[0m')
# Move cursor up 3 lines
print('\x1b[3A')
Sorting and Comparison
ASCII ordering determines how string comparisons work: uppercase letters (65–90) come before lowercase (97–122), and digits (48–57) come before both. This is why 'Z' < 'a' is true in most languages — 'Z' is 90 and 'a' is 97.
Data Encoding
When binary data needs to travel through ASCII-only channels (email, HTTP, URLs), it gets encoded into ASCII-safe representations: Base64 uses characters A–Z, a–z, 0–9, +, and /. Percent-encoding converts bytes to %XX hex sequences using only ASCII characters.
Convert Text to ASCII Online
ZeroTool’s ASCII Converter converts any text to its ASCII (decimal, hex, and binary) representation in real time, and converts codes back to text. It handles the full printable ASCII range and shows the character table for quick reference — no installation needed.