Why Do We Need Text Encoding?
Computers cannot directly understand characters like A, b, ?, or #.
At the lowest level, everything is stored as bits—0s and 1s. To store text, we need a way to map human-readable characters to specific bit patterns. This mapping is called a character encoding.
When you write a document, your computer converts each character—letters, numbers, punctuation, even invisible characters like space or newline—into a long sequence of bits so it can store and process them.
ASCII: A Foundational Character Encoding
In the early days of computing, every device manufacturer used its own system to represent characters. This created chaos—systems couldn't easily share documents or communicate. To solve this, the American National Standards Institute created a universal system: ASCII (American Standard Code for Information Interchange).
ASCII uses 7 bits, providing 128 characters:
- Uppercase and lowercase English letters
- Digits 0–9
- Punctuation
- Control codes like newline or tab
Since computers typically store data in 8‑bit chunks (bytes), ASCII characters are usually stored as 8 bits by adding a leading zero. In early systems, that extra bit was sometimes used for error checking; today it is simply set to zero as padding.
ASCII Lookup Table
When humans talk about ASCII values and which numbers correspond to which characters, we often refer to the characters by both their decimal and their hexadecimal value. The table below shows all 128 ASCII characters used in ASCII.
You don't need to memorize this table — just take a few minutes to explore it and notice the patterns.
Take a few moments to examine the table and the relationship between the decimal, hexadecimal, and the character that they represent. For example, notice that the uppercase letters start with decimal value 65 which is hex value 41 or bit string 010000012. The lowercase letters start with decimal value 97 which is hex value 61 or bit string 011000012.
Notice that there is a difference between the way ASCII stores the character "7" (dec 55, hex 37, 001101112 from the way that we stored the number 7 earlier in this course (000001112). This is an important observation. It helps us recognize that the computer treats those two values very differently and that the character "7" and the number 7 are not interchangeable.
Example: The message "Hello." in ASCII
This means that if we wanted to write down the six character message "Hello." we would store six bit strings:
H →01001000e →01100101l →01101100l →01101100o →01101111. →00101110
Which results in:
01001000 01100101 01101100 01101100 01101111 00101110
Estimating the Size of an ASCII Text File
You may have noticed something that looks like a contradiction: ASCII was designed using 7 bits, which gives 128 possible characters. So why do we say each character costs 8 bits of storage? The answer is that computers store and move data in 8-bit chunks called bytes — that is simply how the hardware is built. A 7-bit value does not fit neatly into that structure, so every ASCII character is padded with a leading zero to fill out a full byte. The character A, for example, is defined in ASCII as 1000001 (7 bits) but is stored in memory as 01000001 (8 bits). The extra zero does not change the meaning; it just fills the byte. This is why we use 8 in the formula rather than 7, and why every ASCII character costs exactly 1 byte of storage.
Because every ASCII character is stored using exactly 8 bits, calculating the size of an uncompressed ASCII file follows the same pattern you will use throughout this topic for images and sound: multiply out the total number of bits, then divide by 8 to convert to bytes.
The formula is:
Size (bytes) = Pages × Lines × Characters × 8 ÷ 8
Notice that 8 ÷ 8 = 1, which is why you will sometimes see this written simply as Pages × Lines × Characters. But keeping the full formula visible is important — it reminds you why the result is 1 byte per character: 8 bits per character, divided by 8 bits per byte. This same structure will reappear with images and sound, where the numbers are less convenient.
Worked Example
How large is an uncompressed ASCII document with 6 pages, 45 lines per page, and 80 characters per line?
| Step | What we are calculating | Result |
|---|---|---|
| 1 | Count the total characters: 6 × 45 × 80 | 21,600 characters |
| 2 | Multiply by bits per character: 21,600 × 8 | 172,800 bits |
| 3 | Convert bits to bytes: 172,800 ÷ 8 | 21,600 bytes |
Check: 6 × 45 × 80 × 8 ÷ 8 = 21,600 bytes ✓
Now You Try
A student writes a short essay that fills 3 pages, with 40 lines per page and 70 characters per line. How large is the uncompressed ASCII file in bytes?
Show answer
| Step | What we are calculating | Result |
|---|---|---|
| 1 | Count the total characters: 3 × 40 × 70 | 8,400 characters |
| 2 | Multiply by bits per character: 8,400 × 8 | 67,200 bits |
| 3 | Convert bits to bytes: 67,200 ÷ 8 | 8,400 bytes |
Check: 3 × 40 × 70 × 8 ÷ 8 = 8,400 bytes ✓
This estimate treats every position in the document as a character, including spaces. Real files also contain a small amount of metadata added by the operating system, but for our purposes this formula gives a reliable estimate of the text content itself.
Where ASCII Falls Short
ASCII works well for English text, but the world uses far more than 128 symbols. Extended ASCII versions added more characters, but they still couldn’t support:
- Many world languages
- Scripts like Chinese, Korean, or Arabic
- Special symbols such as emojis or math notation
Worse, different "extended ASCII" systems weren’t compatible with each other. A document created in one region might display garbled text in another.
Unicode: Supporting All the World's Writing
To support global communication, the computing industry collaborated to create Unicode—a universal system designed to represent every character in every language. Unicode can represent over a million potential characters, covering virtually every writing system in use today.
The most important thing to understand about Unicode for this course is that supporting a much larger character set comes at a cost: Unicode files are larger than ASCII files for the same amount of text, because each character requires more bits to encode.