My Tool Studio
Developer Tools·4 min read

How ASCII Encoding Works: 65, 97, and the 32 Trick

Type the letter A into almost any language, cast it to a number, and you'll get 65. That's not a coincidence, it's a 1963 standard that still sits underneath every string you touch. Understanding how ascii encoding works explains char math, the difference between the character '0' and the number 0, and why flipping one bit changes letter case. This guide walks the 128-code layout, shows the 65 and 97 trick, tours the control characters hiding below 32, and clears up where ASCII ends and Unicode begins.

ASCII Table{"id": 47"ok": true}

Where a 60-year-old character set still bites

ASCII shows up whenever text meets bytes. A parser that behaves until it hits byte 13. A CSV that gains blank lines when it crosses from Linux to Windows. An interview question asking you to lowercase a string without calling a library. All of these resolve against the same 128-entry table from 1963.

Modern languages hide the numbers behind convenient APIs, but the numbers are still down there, and knowing a handful of them by heart makes whole categories of bugs legible at a glance.

How ASCII encoding works in seven bits

128 codes, arranged with intent.

ASCII assigns the numbers 0 through 127 to characters, which fits in seven bits. The layout is deliberate. Codes 0 to 31 are control characters, instructions rather than symbols. Code 32 is space. Digits occupy 48 through 57, uppercase letters run 65 through 90, lowercase runs 97 through 122, and 127 is DEL.

Because those ranges are contiguous, arithmetic on characters is meaningful. Testing whether a character is a digit is a range comparison. Turning the character '7' into the number 7 is a subtraction: 55 minus 48.

65, 97, and the single bit between them

The worked example behind every toLowerCase.

Look up A in the table and you'll find decimal 65, binary 1000001. Look up a and you'll find 97, binary 1100001. The gap is exactly 32, and 32 is bit six. Uppercase and lowercase letters differ by one bit, on purpose.

That's why the classic tricks work everywhere. Adding 32 to 'A' yields 'a'. ORing a letter with 32 forces lowercase, and clearing that bit forces uppercase. C, Java, Python, and JavaScript all agree on the result because each is doing math on the same underlying code values, not on the letters themselves.

Control characters explained without the folklore

The first 32 codes date from teletype hardware, and a few still run the world. 10 is LF, line feed. 13 is CR, carriage return, and Windows pairs them as CRLF while Unix uses LF alone, which is the entire cause of diffs that claim every line changed. 9 is HT, the tab. 27 is ESC, the opening byte of every terminal color sequence. 0 is NUL, the string terminator C made famous.

The table gives each one its official abbreviation, so when a hex dump shows 0x07 you can confirm it's BEL, the character that once rang an actual bell on the receiving machine.

ASCII vs Unicode: a subset, not a rivalry

Unicode didn't replace ASCII so much as absorb it. The first 128 Unicode code points are the ASCII assignments, unchanged, and UTF-8 encodes each of them as the same single byte. Any pure ASCII file is already valid UTF-8, which is the main reason UTF-8 conquered the web.

The practical line in the ascii vs unicode question is 127. At or below it, one character equals one byte and the old arithmetic is safe. Above it, a character can span two to four bytes, and byte-level tricks start corrupting text.

Char math habits that corrupt strings

The same few mistakes account for most character-level bugs:

  • Comparing the character '0' to the integer 0. They're 48 apart, and the mistake compiles cleanly in loosely typed languages.
  • Applying the case-toggle bit to non-letters. OR the at sign (64) with 32 and you get a backtick, not a lowercase anything.
  • Indexing bytes in a UTF-8 string as if each were a character. That assumption holds only while every code stays under 128.
  • Treating codes 128 to 255 as standard ASCII. That range belongs to competing legacy code pages, which is why old files sometimes show two garbled symbols where one accented letter should be.
  • Normalizing line endings by stripping CR but not LF, or the reverse, and shipping files that mix both.

Getting answers faster from the ASCII Table

Search the description column, not just the codes: typing separator surfaces FS, GS, RS, and US at codes 28 through 31, characters that still turn up in data interchange formats. And when you're writing escape sequences, copy from the hex column, because \x41 typed from the table is more reliable than \x41 recalled from memory.

Where the ASCII Table hands off

Character codes sit underneath several neighboring tools. The Base64 Encoder / Decoder turns arbitrary byte sequences into printable ASCII for safe transport. The URL Encoder / Decoder writes unsafe characters as percent escapes built from these same hex values. And the HTML Entity Encoder handles the web's version of the problem, where a less-than sign must travel as an entity to stay text instead of becoming markup.

Try it now

Open ASCII Table

The tool is one click away. No sign up, no upload, no payment.

Open ASCII Table