Why seven bits
ASCII was published in 1963 by the American Standards Association, with a major revision in 1967, so that teleprinters and computers from different makers could exchange text. Seven bits give 2⁷ = 128 codes. That was enough for English letters, digits, punctuation and device controls, and fewer bits meant cheaper transmission.
Patterns hidden in the layout
The order was designed to make common operations cheap. Look at these codes in binary:
A 65 01000001
a 97 01100001
0 48 00110000
5 53 00110101
Upper and lower case differ only in one bit, worth 32, so changing case is a single bit operation. The digits start at 48 with their value in the low four bits, so subtracting 48 converts the character 5 into the number 5. Sorting by code puts digits before capitals and capitals before lowercase, which is why a simple sort lists "Zebra" ahead of "apple".
Control codes still in use
The first 32 codes date from machines that had to be told what to do. Several still matter every day:
- 9 (tab) moves to the next tab stop.
- 10 (line feed) ends a line on Linux and macOS, while Windows files traditionally use 13 then 10.
- 27 (escape) introduces the sequences terminals use for color and cursor movement.
- 0 (null) marks the end of a string in C.
Code 127 sits alone at the far end for a physical reason. On punched paper tape it is all seven holes, so an operator could erase any mistake by punching it out completely. The reader then skipped that position.
Extended ASCII is not one standard
ASCII stops at 127. The eighth bit gave computer makers 128 more codes, and they filled them differently. Code 233 is é in Windows-1252 but Θ in the old IBM PC code page 437. The second table on this page shows Windows-1252, the most common one on the web historically, where five positions were never assigned.
Garbled text such as é in place of é is the classic symptom of a mismatch: the bytes were written as UTF-8 and read as Windows-1252. UTF-8 solved this by matching ASCII exactly for the first 128 codes and using multiple bytes for all other characters, so a pure ASCII file is already valid UTF-8.