ASCII
| Standard | |
|---|---|
![]() Image placeholderPlace the file shown below in the assets/articles folder ascii.webp | |
| Full name | American Standard Code for Information Interchange |
| First published | 1963 |
| Current standard | ANSI X3.4-1986 (reaffirmed) |
| Code size | 7 bits, 128 code points |
| Successor | Unicode (UTF-8 is backwards compatible) |
ASCII, the American Standard Code for Information Interchange, is a character encoding that maps 128 characters to the numbers 0 through 127.[1] Each number fits in seven bits. The set contains the uppercase and lowercase English letters, the ten digits, punctuation marks and 33 control codes originally meant for teleprinters and terminals.
ASCII is among the most influential standards in computing. Almost every modern text encoding, including UTF-8, keeps the ASCII values unchanged, so a plain English text file written in 1970 is still valid today.
History
Work on ASCII began in 1960 in a committee of the American Standards Association, which later became ANSI. Computer makers at the time used dozens of incompatible codes, which made exchanging data between machines awkward. Engineers such as Bob Bemer, who worked at IBM, pushed for a common seven-bit code that could replace them.
The first edition was published in 1963. A major revision in 1967 added lowercase letters and fixed several control codes, and the standard was updated again in 1986. In 1969 the Internet pioneers documented the code for network use in RFC 20, which helped make it the default for early protocols such as Telnet, FTP and email.[1]
Structure of the code
The 128 positions divide into three groups.
| Range (decimal) | Range (hex) | Content |
|---|---|---|
| 0-31 | 00-1F | Control characters (for example NUL, BEL, TAB, LF, CR, ESC) |
| 32 | 20 | Space |
| 33-126 | 21-7E | 94 printable graphic characters |
| 127 | 7F | DEL (delete) |
There are 95 printable characters if the space is counted. The control codes describe actions rather than glyphs: line feed (10) advances the paper, carriage return (13) moves the print head back to the left margin, and bell (7) rings an audible alert. Several of them, such as TAB and newline, are still used every day.
Design details
The layout was chosen with care. Digits start at 0x30, so the character '0' has the value 48 and the numeric value of a digit character is its code minus 48. Uppercase A is 0x41 (65) and lowercase a is 0x61 (97). The two differ in exactly one bit, 0x20, so converting case is a single bit operation.
'A' = 0100 0001 (0x41)
'a' = 0110 0001 (0x61)
^
bit 5 flips the caseThe control characters sit in the first column of the table so that holding the Control key on a keyboard simply clears the upper bits of a letter. Pressing Ctrl+G sends code 7, the bell, because G is 0x47.
Newlines
ASCII defines both carriage return and line feed, and operating systems later disagreed about how to end a line. Unix and its descendants use a single line feed, classic Mac OS used a carriage return, and Windows uses the pair CR+LF. Many network protocols, including HTTP and SMTP, specify CR+LF. Mismatches between these conventions still cause bugs in text tools and version control systems.
Extended ASCII and national variants
Seven bits leave no room for accented letters. An ISO standard, ISO 646, therefore allowed some punctuation positions to be replaced by national characters in different countries, which caused confusion in source code.
When computers moved to eight-bit bytes, vendors used the extra 128 positions for their own purposes. The results are often called "extended ASCII", although they are not part of ASCII itself. Examples include the IBM PC code page 437, ISO 8859-1 (Latin-1), Windows-1252 and many code pages for Greek, Cyrillic and other scripts. Because each one assigned the upper half differently, text could turn into garbled characters when read with the wrong code page. This failure mode is known as mojibake.
Relationship to Unicode and UTF-8
Unicode was created to replace this patchwork with a single set of code points for the world's writing systems. Its first 128 code points are identical to ASCII.[2] UTF-8, defined in RFC 3629, encodes those 128 code points as a single byte with the same value, while all other characters use two to four bytes.[3] A valid ASCII file is therefore also a valid UTF-8 file.
This compatibility is a major reason UTF-8 became the dominant encoding of the web. Programs that only understand ASCII, such as many parsers and command-line tools, continue to work on the ASCII portion of UTF-8 data.
ASCII in practice
Programming languages, file formats and protocols still rely on ASCII for their syntax. Keywords in C and Python, HTTP header names, JSON punctuation and domain names are all ASCII, even when the data inside them is not. Internationalized domain names use an ASCII-compatible encoding called Punycode for this reason.
In Python the mapping is easy to inspect:
>>> ord('A')
65
>>> chr(97)
'a'
>>> 'hello'.encode('ascii')
b'hello'
>>> 'café'.encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characterASCII art
Because ASCII characters have a fixed width in terminal fonts, people have long used them to draw pictures. ASCII art appeared on early printers and bulletin board systems and is still used in source code banners, README files and command-line interfaces. Box-drawing and block characters used in more elaborate terminal art are not ASCII, but belong to Unicode or to older code pages.
Limitations
ASCII only represents English text well. It has no accented letters, no non-Latin scripts and no typographic quotation marks or dashes. These gaps are what led to the many extended code pages, and later to Unicode. Even so, the original 128 characters remain the common core of nearly all text on computers today.
Editorial connections and engineering implications
Control characters and encoding compatibility
ASCII contains control characters as well as printable letters and symbols. Carriage return, line feed, tab and escape originated in communication equipment and terminals, but still appear in text files and protocols. Different operating systems adopted different line-ending conventions, which can cause unexpected differences in source-control comparisons or text processing. These are representation conventions, not differences in the characters themselves.
ASCII's seven-bit range cannot represent most writing systems. Early eight-bit code pages extended it in incompatible ways, so a byte could represent different characters on different machines. Unicode addressed the larger problem through a shared character repertoire, while UTF-8 preserves ASCII's original byte values for the first 128 code points. Modern applications should declare an encoding instead of assuming every input is ASCII. JSON and many internet protocols rely on Unicode text, making explicit encoding a basic interoperability requirement.
See also
- UTF-8 – A variable-width character encoding that represents every Unicode code point using one to four bytes.
- JSON – A lightweight text format for structured data based on JavaScript object syntax.
- HTML – The standard markup language used to structure documents and applications on the World Wide Web.
- POSIX – A family of IEEE standards that specify a portable interface for Unix-like operating systems.
- Python – A high-level, dynamically typed programming language that emphasises readability.
- Release of the IBM PC (1981) – The August 1981 launch of the IBM Personal Computer, which established the dominant PC platform.
- TLS 1.3 – The 2018 version of the Transport Layer Security protocol for encrypted network communication.
References
- ↑ RFC 20: ASCII format for network interchange (rfc-editor.org)
- ↑ The Unicode Standard, Basic Latin block (unicode.org)
- ↑ RFC 3629: UTF-8, a transformation format of ISO 10646 (rfc-editor.org)
