Reading 1 – Text Encoding & ASCII

Meet the cast of "characters" running the whole show.

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:

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.

Dec
Hex
Char
Dec
Hex
Char
Dec
Hex
Char
Dec
Hex
Char
0
00
NUL
32
20
Space
64
40
@
96
60
`
1
01
SOH
33
21
!
65
41
A
97
61
a
2
02
STX
34
22
"
66
42
B
98
62
b
3
03
ETX
35
23
#
67
43
C
99
63
c
4
04
EOT
36
24
$
68
44
D
100
64
d
5
05
ENQ
37
25
%
69
45
E
101
65
e
6
06
ACK
38
26
&
70
46
F
102
66
f
7
07
BEL
39
27
'
71
47
G
103
67
g
8
08
BS
40
28
(
72
48
H
104
68
h
9
09
TAB
41
29
)
73
49
I
105
69
i
10
0A
LF
42
2A
*
74
4A
J
106
6A
j
11
0B
VT
43
2B
+
75
4B
K
107
6B
k
12
0C
FF
44
2C
,
76
4C
L
108
6C
l
13
0D
CR
45
2D
-
77
4D
M
109
6D
m
14
0E
SO
46
2E
.
78
4E
N
110
6E
n
15
0F
SI
47
2F
/
79
4F
O
111
6F
o
16
10
DLE
48
30
0
80
50
P
112
70
p
17
11
DC1
49
31
1
81
51
Q
113
71
q
18
12
DC2
50
32
2
82
52
R
114
72
r
19
13
DC3
51
33
3
83
53
S
115
73
s
20
14
DC4
52
34
4
84
54
T
116
74
t
21
15
NAK
53
35
5
85
55
U
117
75
u
22
16
SYN
54
36
6
86
56
V
118
76
v
23
17
ETB
55
37
7
87
57
W
119
77
w
24
18
CAN
56
38
8
88
58
X
120
78
x
25
19
EM
57
39
9
89
59
Y
121
79
y
26
1A
SUB
58
3A
:
90
5A
Z
122
7A
z
27
1B
ESC
59
3B
;
91
5B
[
123
7B
{
28
1C
FS
60
3C
<
92
5C
\
124
7C
|
29
1D
GS
61
3D
=
93
5D
]
125
7D
}
30
1E
RS
62
3E
>
94
5E
^
126
7E
~
31
1F
US
63
3F
?
95
5F
_
127
7F
DEL

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 → 01001000
e → 01100101
l → 01101100
l → 01101100
o → 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:

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.

A note on Unicode encodings: Unicode is actually implemented in several different ways. The most common you will encounter are UTF-8, which uses a variable number of bytes per character and dominates the modern web, and UTF-16, which uses a fixed 16 bits (2 bytes) per character and is used internally by Windows, Java, and Microsoft Office. For this course we focus on ASCII as the assessable encoding, but it is good to know that UTF-16 exists, that it doubles the storage cost of ASCII for the same text, and that UTF-8 is what you are almost certainly using when you save a file on the modern web.