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. Knowing how the 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 ASCII Table and you'll find decimal 65, hex 0x41, binary 01000001. Look up a and you'll find 97, hex 0x61, binary 01100001. The gap is exactly 32, which is 0x20, and in binary that is a single bit. 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 and a short name, 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. Control characters have no visible symbol, so the Char column shows a dot for them.

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 between the two 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 such as ISO-8859-1 and Windows-1252, 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

Use the filter buttons to cut the table down to one block: Control (0-31, 127), Digits 0-9, Uppercase A-Z, Lowercase a-z, or Space and symbols. Search works on names as well as codes, so typing separator surfaces FS, GS, RS, and US at codes 28 through 31, characters that still turn up in data interchange formats. Hex works too: 0x41 finds A.

When you're writing escape sequences, press Copy next to the hex value rather than recalling it from memory. For web pages, the HTML entity column gives the numeric form, such as A for A, plus the named entities for the ampersand, less-than, greater-than, double quote and apostrophe.

When a file mixes in accented letters or curly quotes, switch the range to Extended 128-255 and pick Windows-1252 or ISO-8859-1 to see which character each byte meant, alongside the UTF-8 bytes the same character takes today. The converter under the table turns a word into its codes, or a row of codes from a hex dump back into text, and the Printable PNG chart gives you a one-page reference for a desk or a slide.

Where the ASCII Table hands off

Character codes sit underneath several neighboring tools. Base64 Decode and Encode 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 Encoder / Decoder 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