Text Encoding Basics
Understand how computers store text, why encodings exist and how modern standards like UTF-8 make global communication possible.
Computers ultimately store every piece of information as numbers. Text encoding defines how letters, numbers, punctuation marks and symbols are converted into those numeric values so they can be stored, transmitted and displayed correctly. Without standardized encodings, sharing text between different operating systems, programming languages and applications would be unreliable.
Modern software relies heavily on Unicode and its UTF family of encodings, making it possible to represent virtually every written language using a single universal standard.
What Is Text Encoding?
Text encoding is a mapping between characters and binary data. Every character is represented by one or more bytes according to the selected encoding scheme.
Character
↓
Code Point
↓
Encoded BytesWhy Encoding Is Necessary
Computers cannot directly store letters such as A, B or あ. Instead, they store numeric values that software interprets according to a particular encoding.
| Character | Stored As |
|---|---|
| A | Numeric value |
| 7 | Numeric value |
| 😊 | Numeric value |
Early Character Encodings
Early computer systems supported only limited character sets. Different regions created their own incompatible encodings, making international text exchange difficult.
What Is ASCII?
ASCII was one of the earliest widely adopted character encodings. It uses 7 bits to represent 128 characters, covering English letters, digits, punctuation and control characters.
| Feature | ASCII |
|---|---|
| Characters | 128 |
| Languages | Primarily English |
| Storage | 7 bits |
ASCII Limitations
ASCII cannot represent accented characters, Cyrillic, Arabic, Chinese, Japanese, emoji or thousands of other symbols required for modern computing.
What Is Unicode?
Unicode is a universal character standard that assigns a unique code point to nearly every character used in modern writing systems. Instead of creating separate encodings for every language, Unicode provides one unified character set.
Unicode itself defines characters rather than how they are stored. Storage is handled by encodings such as UTF-8, UTF-16 and UTF-32.
Unicode Code Points
Each Unicode character receives a unique identifier written as U+ followed by hexadecimal digits.
| Character | Unicode |
|---|---|
| A | U+0041 |
| € | U+20AC |
| 😊 | U+1F60A |
UTF Encodings
UTF stands for Unicode Transformation Format. Different UTF encodings store the same Unicode characters using different numbers of bytes.
| Encoding | Typical Storage |
|---|---|
| UTF-8 | 1–4 bytes |
| UTF-16 | 2 or 4 bytes |
| UTF-32 | 4 bytes |
Why UTF-8 Became the Standard
UTF-8 is backward compatible with ASCII, uses storage efficiently for common text and supports every Unicode character. These advantages made it the dominant encoding for websites, programming languages, APIs and modern operating systems.
Understanding UTF-8
UTF-8 is a variable-length encoding that stores characters using one to four bytes. Common English text remains compact because ASCII characters continue to occupy only a single byte.
| Character Type | Bytes |
|---|---|
| ASCII characters | 1 |
| Most European characters | 2 |
| Many Asian characters | 3 |
| Emoji and rare symbols | 4 |
Understanding UTF-16
UTF-16 stores most common Unicode characters using two bytes, while less frequently used characters require four bytes through surrogate pairs. It is commonly used internally by several operating systems and programming environments.
Understanding UTF-32
UTF-32 stores every Unicode character using exactly four bytes. This simplifies character indexing but consumes significantly more storage than UTF-8 or UTF-16.
| Encoding | Storage Efficiency |
|---|---|
| UTF-8 | Excellent for web content |
| UTF-16 | Balanced |
| UTF-32 | Largest file size |
Choosing the Right Encoding
Most modern applications use UTF-8 because it provides excellent compatibility, efficient storage and universal language support.
- Websites
- HTML
- CSS
- JavaScript
- JSON
- XML
- REST APIs
Encoding Problems
When software interprets text using the wrong encoding, characters may become unreadable. This phenomenon is commonly known as mojibake.
Correct:
Hello
Incorrect:
ЗдравÑтвуйтеThe original data is often intact—the wrong encoding is simply being used during interpretation.
BOM (Byte Order Mark)
Some Unicode files begin with a Byte Order Mark (BOM), a small sequence of bytes that identifies the encoding and, in certain cases, byte order. UTF-8 files may include a BOM, although it is optional and often omitted.
UTF-8 Without BOM
Many development tools recommend saving source code as UTF-8 without a BOM because it avoids compatibility issues with certain compilers, interpreters and command-line tools.
Encoding on the Web
Web pages should explicitly declare UTF-8 so browsers interpret text correctly regardless of operating system or language settings.
<meta charset="UTF-8">Common Encoding Mistakes
- Mixing UTF-8 and legacy encodings.
- Saving files with the wrong encoding.
- Forgetting to declare UTF-8 in HTML.
- Using ASCII for multilingual content.
- Assuming every file uses UTF-8.
Best Practices
Use UTF-8 consistently throughout your project, configure editors to save files in UTF-8, explicitly declare encodings where appropriate and avoid mixing legacy character sets with Unicode whenever possible.
Frequently Asked Questions
What is text encoding?
Text encoding is a method of converting characters into binary data so computers can store, process and transmit text correctly. Different encodings define different mappings between characters and bytes.
What is the difference between Unicode and UTF-8?
Unicode is a universal character standard that assigns code points to characters. UTF-8 is one of several encoding formats used to store those Unicode characters as bytes.
Why is UTF-8 the most common encoding?
UTF-8 is compact for English text, fully supports every Unicode character, remains backward compatible with ASCII and is supported by virtually every modern operating system, browser and programming language.
What causes unreadable characters like 'é' or 'Ð'?
These characters usually appear when text is interpreted using the wrong encoding. The original data may still be correct, but the application is decoding it incorrectly.
Should I still use ASCII today?
ASCII is suitable only for simple English text. For modern software, websites and multilingual content, UTF-8 is almost always the recommended choice.
Helpful Encoding Tools
A UTF-8 Inspector displays the byte representation of UTF-8 encoded text, a UTF-16 Inspector shows how characters are stored using UTF-16 code units, a UTF-32 Inspector demonstrates fixed-width Unicode storage, an ASCII Converter converts compatible text to and from the ASCII character set, and a Unicode Escape Converter transforms Unicode characters into escape sequences commonly used in programming languages and data formats.
Conclusion
Text encoding is a fundamental part of modern computing because every character must ultimately be represented as binary data. While early standards such as ASCII supported only a limited range of characters, Unicode and UTF encodings made it possible to represent virtually every writing system using a unified standard. Understanding the differences between UTF-8, UTF-16 and UTF-32, recognizing common encoding problems and consistently using UTF-8 throughout your projects helps ensure that text is stored, transmitted and displayed correctly across browsers, operating systems and programming languages.