ASCII Encoding Explained: Text, Decimal, Hex, Binary and Octal
ASCII maps every printable character to a number between 0 and 127. Understanding those numbers — in decimal, hex, binary, and octal — is a skill every developer reaches for more often than expected.
What Is ASCII?
ASCII stands for American Standard Code for Information Interchange. It was published in 1963 and defines a mapping between 128 characters and the integers 0 through 127. Those 128 characters cover the English alphabet (upper and lower case), digits 0–9, punctuation, and 33 control characters like newline, tab, and carriage return.
Every character you type in an English-language program — every function name, every string literal, every file path — is represented under the hood as an ASCII number. The concept predates modern computers but still sits at the foundation of every encoding system used today.
Why Developers Still Need ASCII
You might expect ASCII to be a solved problem by now. It mostly is — but these situations come up regularly:
- Reading binary files: When you open a file in a hex editor, the right panel shows the ASCII interpretation of each byte. Knowing that
0x48 0x54 0x54 0x50spells "HTTP" is instant orientation. - Debugging network protocols: Raw TCP and HTTP traffic is ASCII text. A packet capture becomes readable the moment you know your way around the table.
- URL encoding: A space is ASCII 32, which is
0x20in hex, which is why a space in a URL becomes%20. The percent sign is followed by the hex value of the ASCII code. - Escape sequences:
\nis ASCII 10 (line feed),\tis ASCII 9 (horizontal tab),\ris ASCII 13 (carriage return). When a log file looks broken, one of these is usually responsible. - Legacy systems: Mainframes, embedded firmware, serial protocols, and countless file formats were designed around ASCII. Working with them means thinking in ASCII.
The Four Number Systems, With One Example
The letter A is the cleanest example because its values are easy to remember across all four systems.
| System | Value for "A" | How to read it |
|---|---|---|
| Decimal | 65 |
Base 10, the number you count with |
| Hexadecimal | 0x41 |
Base 16; 4×16 + 1 = 65 |
| Binary | 01000001 |
Base 2; the actual bits stored in memory |
| Octal | 101 |
Base 8; 1×64 + 0×8 + 1 = 65 |
Lowercase a is decimal 97 (0x61, 01100001 binary). The difference between uppercase and lowercase is exactly 32 — which is 0x20, the same value as a space. This is not a coincidence: it was a deliberate design choice that makes case conversion a single bit flip.
Decimal
Decimal is what most humans reach for first. The full printable ASCII range runs from 32 (space) to 126 (tilde ~). Values 0–31 and 127 are control characters — most are invisible, but several (9, 10, 13) appear constantly in text files and network streams.
Hexadecimal
Hex is the format you will see most often in technical contexts: memory dumps, color codes, byte sequences in packet captures, and escape sequences like \x41. A single ASCII character always fits in exactly two hex digits, which makes hex the compact, readable format for byte-level work.
Binary
Binary is what the hardware actually stores. ASCII values 0–127 fit in 7 bits, which is why the original ASCII specification used 7-bit codes. Modern storage rounds up to 8 bits (one byte), with the high bit set to zero for standard ASCII. Understanding the bit pattern matters when you work with bitwise operations, serial protocols, or compression formats.
Octal
Octal was more common when computer word sizes were multiples of 3 bits. You still encounter it in Unix file permissions (chmod 755), C/Python string literals (\101 for "A"), and some older network protocols. Three octal digits map to exactly 9 bits — a convenient split for old architectures.
Practical Examples
URL Encoding
When a browser encodes a URL, it looks up the ASCII value of each unsafe character and writes it as a percent sign followed by two hex digits. Space (ASCII 32 = 0x20) becomes %20. The exclamation mark (ASCII 33 = 0x21) becomes %21. Understanding this makes URL encoding transparent rather than magic.
Use the URL Encoder/Decoder to encode or decode any URL string instantly.
Escape Sequences in Code
Every language that uses backslash escapes is referencing ASCII values:
\n— ASCII 10, line feed. Moves the cursor down one line.\r— ASCII 13, carriage return. Windows line endings are\r\n(13 then 10).\t— ASCII 9, horizontal tab.\0— ASCII 0, null. The string terminator in C.\x41— Hex escape for ASCII 65, the letter "A".
When you see garbled output or unexpected line breaks in a file, checking the raw ASCII values of the offending bytes is the fastest way to diagnose it.
Reading Binary Files
PNG files start with the bytes 89 50 4E 47 0D 0A 1A 0A in hex. The middle four bytes — 50 4E 47 — are ASCII for "PNG". ZIP files start with 50 4B 03 04: "PK" (the initials of Phil Katz, who wrote the format). These signatures let you identify file types without relying on the file extension.
Extended ASCII and Why It Was Not Enough
Standard ASCII covers only 128 characters — enough for English but nothing else. Various "extended ASCII" schemes used the 8th bit to add another 128 characters (128–255), covering Western European languages, drawing characters, and other symbols. The problem: there was no single standard. Code page 437 (original IBM PC), Latin-1 (ISO 8859-1), and Windows-1252 all used the same byte range for different characters.
This is why opening a file written on one system in a different locale produces garbage characters. The bytes are the same; the interpretation differs.
Unicode solved this by assigning a unique number (code point) to every character in every writing system — over 140,000 characters today. UTF-8, the dominant encoding on the web, is backward-compatible with ASCII: the first 128 Unicode code points have the same values as ASCII, stored in a single byte with the high bit zero. Any valid ASCII file is also valid UTF-8.
Related Tools
If you are working with binary data alongside ASCII, the Binary to Text Converter converts raw binary strings directly to readable text. For converting between number bases in bulk, the Number Base Converter handles decimal, hex, binary, and octal for any number.
Frequently Asked Questions
What is the ASCII value of a space?
Space is ASCII 32 (decimal), 0x20 (hex), 00100000 (binary), 040 (octal). It is the lowest printable ASCII character — everything below 32 is a control character.
Why is "A" decimal 65 and not 1?
Values 0–31 are reserved for control characters, and 32 is space. The printable characters start at 33 with the exclamation mark. Digits 0–9 are at positions 48–57, uppercase letters A–Z at 65–90, and lowercase a–z at 97–122.
What is the difference between ASCII and Unicode?
ASCII defines 128 characters. Unicode defines over 140,000. The first 128 Unicode code points are identical to ASCII, so UTF-8 encoded ASCII text looks byte-for-byte identical to plain ASCII. Unicode extends the system; it does not replace what ASCII already defined.
Why does %20 mean space in URLs?
Percent-encoding takes the ASCII value of the character, converts it to hexadecimal, and prefixes it with %. Space is ASCII 32, which is hex 20, so the encoded form is %20. The same rule applies to every other character that is not safe in a URL.
How do I convert text to ASCII values in code?
In most languages, you access the character code directly: ord("A") in Python, "A".charCodeAt(0) in JavaScript, (int)'A' in C. For the reverse, chr(65) in Python, String.fromCharCode(65) in JavaScript, (char)65 in C.
Convert Any Text to ASCII Now
Paste any text and instantly see decimal, hex, binary, and octal values for every character.