Character encoding
A character encoding is a rule for turning written characters, such as letters, digits, punctuation marks, and symbols, into numbers that a computer can store and send. Each character gets a number, and that number is stored as one or more bytes. A program that reads the bytes must use the same rule, or the text comes out garbled.[1][2]
Encodings have grown to cover more of the world's writing over time.
- Early encodings such as ASCII had only 128 codes and covered the unaccented letters A to Z.[3][4]
- Later encodings added characters for other languages.[5][4]
- Unicode brought them together in one set that aims to give every character in the world's writing systems its own number.[1]
- Its UTF-8 form is now used by about 99 percent of websites whose encoding is known.[6]
Characters, code points, and bytes
Computers store only numbers, so text needs an agreed way to turn characters into numbers. A coded character set gives each character a unique number, called its code point. A character encoding then says how each code point is stored as bytes.[1]
- A bit is a single binary digit, 0 or 1.
- A byte is a group of 8 bits, so it can hold 256 different values.[7][5]
- Code points are usually written in hexadecimal, a base-16 notation. Unicode writes them as "U+" followed by hex digits, so the letter A is U+0041 and á is U+00E1 (225 in decimal).[1]
The same byte can mean different things
A byte has no meaning by itself. ISO/IEC 8859 is a family of 8-bit encodings, where ISO 8859-1 covers Western European languages and ISO 8859-5 covers Cyrillic.[8][9] The byte value 233 stands for é in ISO 8859-1, but in ISO 8859-5 the same value stands for the Cyrillic letter щ.[2]
Only the choice of encoding tells a program which character is meant.[2]
Telegraph codes
Character encoding began with the telegraph, long before computers. In 1835 Samuel Morse created a system of dots and dashes for letters and numbers, and his partner Alfred Vail improved it so that the most common letters got the shortest codes.[10] Morse code is variable-length, because different letters use different numbers of signals.
The Baudot code, developed by Émile Baudot in France, used fixed groups of five on-and-off signals of equal length. Five signals give 32 combinations, one per character.[11]
By the mid-20th century the Baudot code had replaced Morse code for most printing telegraphy.[11]
Fixed-length codes set the pattern that computers still follow. A code of bits can name
different characters, where is the number of possible codes.
- 5 bits give 32 codes.
- 7 bits give 128 codes.
- 8 bits give 256 codes.
ASCII
ASCII, the American Standard Code for Information Interchange, is a 7-bit code with 128 characters.[3] Most modern character encodings are based on ASCII.[12] Windows code pages (numbered character encodings) and Unicode keep its codes for those 128 characters.[5][13]
History
ASCII was developed by the X3.2 subgroup of the American Standards Association, which first met on October 6, 1960.[14][12]
Bob Bemer submitted his proposal for a common computer code in May 1961.[12] According to Eric Fischer's history of character codes, the agreed code was based on a proposal by Robert W. Bemer, Howard J. Smith, and F. A. Williams.[14]
The first edition, ASA X3.4-1963, was published on June 17, 1963.[12][14] The current version is ANSI X3.4-1986, issued through the American National Standards Institute (ANSI). It was renamed INCITS 4-1986 after the X3 committee became INCITS in 1996.[3]
Code layout
Of the 128 codes, 33 are control codes and 95 are printable characters, counting the space.[15]
| Codes (decimal) | Codes (hex) | Contents |
|---|---|---|
| 0 to 31 | 00 to 1F | Control codes |
| 32 | 20 | Space |
| 33 to 47 | 21 to 2F | Punctuation and symbols |
| 48 to 57 | 30 to 39 | Digits 0 to 9 |
| 58 to 64 | 3A to 40 | Punctuation and symbols |
| 65 to 90 | 41 to 5A | Uppercase A to Z |
| 91 to 96 | 5B to 60 | Punctuation and symbols |
| 97 to 122 | 61 to 7A | Lowercase a to z |
| 123 to 126 | 7B to 7E | Punctuation and symbols |
| 127 | 7F | DEL (a control code) |
The table puts related characters in blocks. The digits run in order, and A to Z and a to z form two unbroken runs.[15][16] Each lowercase letter differs from its uppercase form by a single bit, the one worth 32. For example, A is 1000001 in binary (65) and a is 1100001 (97).[15]
Control codes
Codes 0 to 31 and 127 are the control codes, which signal actions instead of printing anything.[17] Two of them, line feed (code 10) and carriage return (code 13), are used alone or together to mark the end of a line.[17][18]
| Operating system | Line ending |
|---|---|
| Unix | Line feed (10) |
| Windows | Carriage return (13) then line feed (10) |
From 7 bits to 8
Computers came to store data in 8-bit bytes, which left one bit of each byte unused by ASCII. RFC 20, an early network standard, put 7-bit ASCII in an 8-bit byte whose top bit is always 0.[15] That free top bit later made room for 128 extra characters, as the section on code pages explains.
EBCDIC
EBCDIC, the Extended Binary Coded Decimal Interchange Code, is IBM's 8-bit encoding for its mainframe computers. The IBM System/360 family, launched on April 7, 1964, used it to represent text.[19][20]
Origins in punched cards
EBCDIC grew out of BCDIC, a 6-bit code based on punched cards. On a card, a digit was one hole in a digit row, and a letter was a hole in a zone row plus one or two holes in the digit rows.[20]
BCDIC used its low four bits for the digit rows and its high two bits for the zone rows.[20]
Differences from ASCII
EBCDIC gives characters different numbers than ASCII does, so text must be converted when it moves between the two.[16]
| Character | EBCDIC (hex) | ASCII (hex) |
|---|---|---|
| A | C1 | 41 |
| B | C2 | 42 |
| a | 81 | 61 |
| 1 | F1 | 31 |
| space | 40 | 20 |
The sort order and layout of the alphabet also differ.[16]
| Property | EBCDIC | ASCII |
|---|---|---|
| Order from lowest to highest | Space, punctuation, lowercase, uppercase, digits | Space, punctuation, digits, uppercase, lowercase |
| Lowercase a compared with A | a is lower than A | a is higher than A |
| Digits compared with letters | Digits are higher than all letters | Digits are lower than all letters |
| Letters A to Z | Gaps between some letters | One unbroken run |
| Z minus A | 40 | 25 |
Use today
EBCDIC is still in use. IBM's z/OS operating system stores its data sets in EBCDIC.[16]
Code pages
A code page is a numbered character encoding, such as code page 1252.[5] Windows code pages and OEM code pages keep ASCII in codes 0 to 127 and use codes 128 to 255 for extra characters, each filling the upper half differently for one language or group of languages.[5] The term is also used loosely for any character encoding scheme.[7]
- ISO/IEC 8859. A series of 8-bit single-byte standards. Part 1, Latin alphabet No. 1, was first published in 1987 for Western European languages; other parts cover scripts such as Cyrillic, Greek, Arabic, and Hebrew.[8][9]
- Windows code pages. Windows-1252 is the usual code page for English and Western European languages. It was based on an ANSI draft that became ISO 8859-1, but it is not exactly the same.[5]
- OEM code pages. OEM stands for original equipment manufacturer. These code pages were originally used for MS-DOS and are still used by console programs; their upper half holds line-drawing and punctuation characters. Code page 437 is the usual one for English.[5]
- EBCDIC code pages. IBM made national variants of EBCDIC, such as code page 037 for the US and Canada. These do not keep ASCII in codes 0 to 127.[9][16]
Code pages cause three problems.
- The same byte means different characters on different code pages, so converting between them can corrupt data.[5]
- No code page holds every character, so converting from Unicode can lose data.[5]
- Mixing encodings in one web page or database is usually impossible, which makes text in multiple languages hard to handle.[1]
Multibyte encodings for East Asian scripts
Chinese, Japanese, and Korean use thousands of characters, far more than 256. Double-byte character sets (DBCS) handle this with lead bytes. Certain byte values above 127 do not stand for a character by themselves, but combine with the next byte, the trail byte, to name one.[5]
The main East Asian encodings have Windows code page numbers of their own.[9]
| Encoding | Script | Windows code page |
|---|---|---|
| Shift JIS | Japanese | 932 |
| GB2312 | Simplified Chinese | 936 |
| Big5 | Traditional Chinese | 950 |
| EUC-KR | Korean | 51949 |
| GB18030 | Simplified Chinese, up to 4 bytes | 54936 |
Some encodings use more than two bytes per character, as GB18030 does.[5][9]
Others, such as the ISO 2022 family, switch between character sets in the middle of text. They use shift bytes or escape sequences, special bytes or byte sequences that are not characters but tell the reader which character set comes next.[7][9]
Unicode
Unicode is a single character set that aims to include every character needed for any writing system, including ancient scripts such as cuneiform. It is now basic to the web and to operating systems.[1]
Origins
Unicode began in late 1987 as a project of Joe Becker, Lee Collins, and Mark Davis, engineers from Xerox and Apple.[21]
Unicode, Inc. was formed on January 3, 1991, to promote a fixed-width, 16-bit encoding for over 60,000 characters, meaning that every character would take the same 16 bits. Version 1.0 appeared that year.[21][22]
Also in 1991, the ISO group behind the ISO/IEC 10646 standard and the Unicode Consortium agreed to build one shared standard. They keep their character codes in sync.[23]
Sixteen bits turned out to be too few, and the standard has grown beyond them.[21] Version 17.0, released in 2025, defines 159,801 characters.[24]
The code space
Unicode code points run from 0 to 10FFFF in hexadecimal, which gives 1,114,112 code points. The space is divided into 17 planes of 65,536 code points each.[13] Plane 0, the Basic Multilingual Plane (BMP), holds most common characters, and the other 16 planes hold supplementary characters.[1]
- 2,048 code points, U+D800 to U+DFFF, are surrogates. They are reserved for UTF-16 and never stand for characters alone.[13][25]
- All code points except the surrogates are called Unicode scalar values. There are 1,114,112 − 2,048 = 1,112,064 of them.[13]
- The first 128 code points match ASCII, and Unicode follows the ISO 8859-1 layout up to U+00FF.[13][26]
Unicode encoding forms
Unicode defines three ways to store code points, called encoding forms: UTF-8, UTF-16, and UTF-32. Each stores a code point as one or more code units, which are integers of a fixed size of 8, 16, or 32 bits.[13] All three can store every Unicode character, and each is an equally valid choice.[13]
UTF-8
UTF-8 uses one to four bytes per character. The first byte shows how many bytes the character takes, and every following byte starts with the bits 10.[27]
| Code point range | Bytes | Bit pattern |
|---|---|---|
| U+0000 to U+007F | 1 | 0xxxxxxx |
| U+0080 to U+07FF | 2 | 110xxxxx 10xxxxxx |
| U+0800 to U+FFFF | 3 | 1110xxxx 10xxxxxx 10xxxxxx |
| U+10000 to U+10FFFF | 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
The x positions hold the bits of the code point.[27] The 3-byte row is used only for code points that are not surrogates.[13] For é (U+00E9), the 11 bits of the code point are 00011 101001, so the bytes are 11000011 10101001, or C3 A9 in hex.[28]
- ASCII transparency. Code points U+0000 to U+007F become the single bytes 00 to 7F, exactly as in ASCII, and those byte values never appear inside any other character.[13]
- Self-synchronization. Every byte that does not start with 10 begins a character, so a program can find character boundaries from any point in a stream.[29]
- No byte order. UTF-8 is a sequence of single bytes, so it has none of the byte-order problems of UTF-16 and UTF-32.[25]
Ken Thompson designed UTF-8 in September 1992 with Rob Pike, according to Pike's account, after an X/Open committee asked them to review its own proposal.[29] Within days they had converted their Plan 9 operating system to the new encoding. Their first version allowed sequences of up to six bytes.[29]
RFC 3629, published in 2003, limited UTF-8 to code points up to U+10FFFF, which need at most four bytes.[27]
UTF-16
UTF-16 uses one 16-bit code unit for each non-surrogate code point in the BMP and a pair of code units, called a surrogate pair, for each supplementary code point.[13] It descends from the original 16-bit design of Unicode, and surrogates were added later to reach code points above U+FFFF.[13]
For a code point from U+10000 to U+10FFFF, the pair is
Here is a 20-bit number from 0 to FFFFF, is the high (leading) surrogate in the range D800 to DBFF, and is the low (trailing) surrogate in the range DC00 to DFFF.[25] For U+233B4, is 133B4, which gives the pair D84C DFB4.[1]
UTF-16 is common in Windows, where most applications handle text internally as UTF-16.[5]
UTF-32
UTF-32 stores every Unicode scalar value in one 32-bit code unit whose value equals the code point; surrogate code points are excluded.[13] Every character takes four bytes, so the form is fixed-width but uses the most space.[1]
Comparing the three forms
The table shows the bytes each form uses for four characters. UTF-16 and UTF-32 bytes are shown in big-endian order, with the most significant byte first.[1][25]
| Character | Code point | UTF-8 | UTF-16 | UTF-32 |
|---|---|---|---|---|
| A (Latin) | U+0041 | 41 | 00 41 | 00 00 00 41 |
| א (Hebrew alef) | U+05D0 | D7 90 | 05 D0 | 00 00 05 D0 |
| 好 (Han ideograph) | U+597D | E5 A5 BD | 59 7D | 00 00 59 7D |
| 𣎴 (Chinese, "stump of tree") | U+233B4 | F0 A3 8E B4 | D8 4C DF B4 | 00 02 33 B4 |
Byte order and the byte order mark
A 16-bit or 32-bit code unit takes several bytes, and systems differ in which byte comes first. This is called endianness. Big-endian order puts the most significant byte first, and little-endian order puts the least significant byte first.[25]
UTF-16 and UTF-32 therefore each come in three variants: BE (big-endian), LE (little-endian), and unmarked. Unmarked text is big-endian by default but may start with a byte order mark that shows its actual order.[25]
The byte order mark (BOM) is the character U+FEFF placed at the start of the data. Its byte-reversed form, U+FFFE, is not a character, so a reader can tell the byte order from the first bytes.[7]
| BOM bytes | Encoding form |
|---|---|
| FE FF | UTF-16, big-endian |
| FF FE | UTF-16, little-endian |
| 00 00 FE FF | UTF-32, big-endian |
| FF FE 00 00 | UTF-32, little-endian |
| EF BB BF | UTF-8 |
In UTF-8 a BOM only signals that the text is UTF-8, since UTF-8 has a single byte order. It can break formats that expect specific ASCII characters at the start, such as the "#!" line of Unix shell scripts.[25]
Wrong encodings and garbled text
Reading bytes with the wrong encoding produces wrong characters, an effect sometimes called mojibake.[30] A common case is UTF-8 text read as Windows-1252 or ISO 8859-1. The letter é is stored as C3 A9 in UTF-8, and a single-byte decoder reads those two bytes as à and ©, so "café" turns into "café".[28]
Mismatches are prevented by declaring the encoding along with the data. On the web, a server can send it in an HTTP (Hypertext Transfer Protocol) header, a line of information sent along with the page, as in Content-Type: text/html; charset=UTF-8.[1] Declaring an encoding does not change the bytes, so the text must also be saved in that encoding.[2]
A missing glyph is a different fault. If the font has no shape for a character, the program shows a box, a question mark, or a glyph from another font, even though the encoding was read correctly.[2]
Sending text through 7-bit channels
Some older systems could carry only 7-bit data. In email, an SMTP client may not send bytes above 7F unless the server supports 8BITMIME, an SMTP extension that lets messages carry 8-bit data.[31] Systems that handle 8-bit character data correctly are called 8-bit clean.[32]
To pass such channels, data is rewritten using only safe ASCII characters. Unicode's model calls this a transfer encoding syntax, a change to bytes that can be undone and that avoids values a protocol (a set of rules for exchanging data) might damage.[7] These methods are binary-to-text encodings.
| Scheme | Converts | Output characters | Main use |
|---|---|---|---|
| Base64 | 3 bytes to 4 characters | 64 ASCII characters, plus = for padding | Binary data in text channels |
| Ascii85 | 4 bytes to 5 characters | ! (33) to u (117), plus z | PDF files |
| Punycode | A Unicode string to an ASCII string | ASCII kept as is; other characters written as letters, digits, and hyphens | Internationalized domain names |
Base64
Base64 turns every three bytes into four characters, so the output is about one third larger than the input.[33]
- Read the input 24 bits (three bytes) at a time.
- Split each 24-bit group into four 6-bit groups.
- Use each 6-bit value, a number from 0 to 63, to pick one of 64 printable characters.
- If the last group is short, fill it with zero bits and pad the output with = signs to a multiple of four characters.[33]
Ascii85
Ascii85 treats each 4 bytes as one base-256 number and rewrites it as five base-85 digits:[34]
Here to are the input bytes and to are digits from 0 to 84.[34]
Adding 33 to each digit gives a printable character from ! to u. A group of four zero bytes becomes the single letter z.[34]
Base 85 is the smallest that works, because (about 4.44 billion) is at least (about 4.29 billion) while is smaller. Five characters for every four bytes make the output only a quarter larger than the input.
Punycode
Punycode turns a Unicode string into an ASCII string in a way that can be undone. ASCII characters in the input are copied as they are, and non-ASCII characters are written using only letters, digits, and hyphens, the characters allowed in host name labels.[35]
It exists for internationalized domain names, where the Domain Name System limits each label to 63 characters.[35]
Punycode is not designed for any other purpose, and its standard says it is not designed for processing free text.[35]
The layered encoding model
Unicode Technical Report 17 splits character encoding into four levels and treats transfer encoding as a separate step outside the model.[7]
- Abstract character repertoire. The set of characters to encode, with no set order. Unicode's repertoire is open, so new characters can be added, while most older encodings have a fixed repertoire.
- Coded character set. A mapping from those characters to integers that are zero or positive, the code points, which need not form one unbroken range.
- Character encoding form. A mapping from those integers to sequences of code units, such as 8-bit bytes or 32-bit words. UTF-8, UTF-16, and UTF-32 are defined at this level.
- Character encoding scheme. A mapping from code units to a sequence of bytes, which fixes the byte order of code units wider than a byte. UTF-16BE and UTF-16LE differ only at this level.
- Transfer encoding syntax. A change to bytes that can be undone, such as Base64 or quoted-printable, used to pass protocols that would damage certain byte values.
For single-byte encodings such as ISO 8859-1, the levels collapse into one simple mapping. The letter A sits at position 65 in the set and is stored as a byte with the value 65.[1]
Characters made of several code points
A code point is not always what a reader sees as one character. The Vietnamese letter ề can be written as three code points: e (U+0065), a combining circumflex (U+0302), and a combining grave accent (U+0300).[1] Unicode groups such sequences into grapheme clusters, units that software should keep together when moving the cursor, selecting text, or breaking lines.[1]
Emoji show the same gap. The family emoji has its own code point, U+1F46A, but it can also be built from separate man, woman, and boy emoji joined by U+200D, and systems that support this show one combined image.[1]
Characters also differ from glyphs, the shapes a font draws. One code point can use several glyphs, and several code points can share one glyph.[1]
For these reasons, the W3C advises that "character" in a technical specification should mean a code point unless the term is defined otherwise.[1]
UTF-8 today
Google reported that in December 2007 Unicode became the most frequent encoding on the web pages it indexed, overtaking both ASCII and Western European encodings.[4]
In October 2026, W3Techs found UTF-8 on 99.1 percent of websites whose encoding it knew, with ISO 8859-1 next at 0.8 percent.[6]
The WHATWG Encoding Standard, which defines how web browsers decode text, requires UTF-8 for new protocols and formats and treats the other encodings as older ones.[36] Older encodings remain where existing data and programs depend on them, such as EBCDIC on IBM mainframes and code pages in older Windows software.[16][5]
References
- Character encodings: Essential concepts, W3C, 2025.
- Character encodings for beginners, W3C.
- ANSI Art and ASCII Art: Origins in Standards, American National Standards Institute.
- Moving to Unicode 5.1, Mark Davis, Official Google Blog, 2008.
- Code Pages, Microsoft Learn, 2021.
- Usage statistics of character encodings for websites, W3Techs, 2026.
- Unicode Technical Report #17: Unicode Character Encoding Model, Unicode Consortium, 2022.
- ISO 8859-1:1987 Information processing: 8-bit single-byte coded graphic character sets, Part 1: Latin alphabet No. 1, ISO, 1987.
- Code Page Identifiers, Microsoft Learn.
- Telegraph, Encyclopaedia Britannica, 2026.
- Baudot Code, Encyclopaedia Britannica, 2021.
- First edition of the ASCII standard is published, Centre for Computing History.
- The Unicode Standard 17.0, Chapter 2: General Structure, Unicode Consortium, 2025.
- The Evolution of Character Codes, 1874-1968, Eric Fischer.
- RFC 20: ASCII format for network interchange, IETF, 1969.
- The EBCDIC character set, IBM, 2010.
- RFC 2326: Real Time Streaming Protocol (RTSP), IETF, 1998.
- The Unicode Standard 17.0, Chapter 5: Implementation Guidelines, Unicode Consortium, 2025.
- The IBM System/360, IBM.
- The IBM 029 Card Punch, Two-Bit History, 2018.
- Summary narrative: history of Unicode, Unicode Consortium.
- Enumerated Versions of the Unicode Standard, Unicode Consortium.
- FAQ: Unicode and ISO 10646, Unicode Consortium.
- The Unicode Standard, Version 17.0.0, Unicode Consortium, 2025.
- FAQ: UTF-8, UTF-16, UTF-32 and BOM, Unicode Consortium.
- The Unicode Standard 17.0, Chapter 7: Europe I, Unicode Consortium, 2025.
- RFC 3629: UTF-8, a transformation format of ISO 10646, IETF, 2003.
- UTF-8 Encoding Debugging Chart, I18nQA.
- The history of UTF-8 as told by Rob Pike, Rob Pike (email archive), 2003.
- Internationalization Best Practices for Spec Developers, W3C.
- RFC 6152: SMTP Service Extension for 8-bit MIME Transport, IETF, 2011.
- Sun Global Glossary: 8-bit clean, Sun Microsystems / Oracle.
- RFC 4648: The Base16, Base32, and Base64 Data Encodings, IETF, 2006.
- PDF Reference, version 1.7, Adobe Systems, 2006.
- RFC 3492: Punycode: A Bootstring encoding of Unicode for IDNA, IETF, 2003.
- Encoding Standard, WHATWG.
