Google Play badge

ascii


ASCII: How Computers Store Letters and Symbols

The big idea

Computers use numbers. People use letters and symbols. We need a bridge. ASCII is that bridge. ASCII turns each letter or symbol into a number. The computer stores the number. When we read, the computer shows the letter again. This is how text works in many files and apps.

Why computers need a code

A computer works with electricity. It sees two states. On and Off. We call these states bits. A bit is a 0 or a 1. Many bits together make bigger numbers. Eight bits make a byte. With bits, we can count. With counting, we can name things. ASCII uses counting to name letters and symbols.

One bit makes two choices. Two bits make four choices. In math, this idea is shown as \(\;2^n\). For \(n=7\), we get \(2^7 = 128\) choices. For \(n=8\), we get \(2^8 = 256\) choices. ASCII uses 7 bits. That gives 128 named items. People later made 8-bit sets with 256 items. Those are called extended ASCII.

What ASCII means

ASCII stands for American Standard Code for Information Interchange. It started in the 1960s. It was made for early printers, teletypes, and computers. It gives each letter, number, space, and some symbols a number. It also gives special numbers to actions like new line. The first version used 7 bits, so it had numbers from 0 to 127.

What is inside ASCII
Simple map examples

Notice something neat. Lowercase letters are 32 more than their uppercase pair. For example, \(\;97 - 65 = 32\). So 'a' is 32 more than 'A'. 'b' is 32 more than 'B', and so on. This pattern makes some computer tasks easy.

Control characters in plain words

When you press the Enter key, your computer may send LF, or CR, or both, depending on the system. Many internet tools use LF. Some old systems used CR and LF together.

Decimal, binary, and hex views

We can write numbers in different ways. Decimal is the normal way we count, using digits 0 to 9. Binary uses only 0 and 1. Hex (hexadecimal) uses 0 to 9 and A to F.

How does binary make 65 for 'A'? Look at the bits in 01000001. The leftmost bit is for 128. Then 64, 32, 16, 8, 4, 2, 1. Only 64 and 1 are on. So \(01000001_{(2)} = 0\times128 + 1\times64 + 0\times32 + 0\times16 + 0\times8 + 0\times4 + 0\times2 + 1\times1 = 65\).

From keyboard to screen

Press a key. The keyboard sends a code to the computer. The system turns it into a character number. For many keys, that number is the ASCII number. The app stores the number in memory. When it shows the text, it looks up the number and draws the letter. When you save, the numbers go into the file.

How text travels across a network

Think of the message Hi!. The letters are H, i, and !. Their ASCII numbers are 72, 105, and 33. In binary, they are 01001000, 01101001, and 00100001. The network sends these bits. The other side reads the bits. It sees the numbers. It shows H, i, and ! again. That is how simple text messages move.

Extended ASCII and code pages

People wanted more symbols. They wanted letters like é, ñ, and ø. They wanted money signs like €. The 7-bit set had only 128 symbols. So people used 8 bits. With 8 bits, we get \(2^8 = 256\) symbols. The top half, from 128 to 255, was used for extra letters and symbols. But there was a problem. Different groups chose different numbers for those extra letters. These choices are called code pages.

Because code pages differ, the same number can show a different symbol on another computer. This mix-up is called mojibake. It looks like strange characters. This is one reason the world moved to Unicode.

ASCII and Unicode

Unicode is a big standard that can show many languages, math symbols, and emoji. It has space for more than a million symbols. There are many ways to store Unicode. One popular way is UTF-8.

How many bytes does text use

With ASCII-only text, each character uses one byte. So the word cat uses 3 bytes. The phrase hi mom has 6 characters including the space, so it uses 6 bytes. In simple math, \(\textrm{ASCII bytes} = \textrm{number of characters}\).

Sorting order with ASCII

Computers often sort strings by their character numbers. ASCII order groups things in a certain way.

This means Zoo comes before apple if we compare simple ASCII values. The sort is by numbers, not by how words sound.

Common ASCII codes to know

Notice the ampersand is &. Its ASCII number is 38. The plus sign + is 43. The minus sign - is 45.

Real uses in everyday tech
ASCII patterns that help
How pictures can be made with ASCII

People make pictures using only characters. This is called ASCII art. Here is a tiny face made with ASCII characters.

:-) Simple smile
(^_^) Friendly face
o_O Surprised

Each face is just characters like colon, dash, and parentheses. No colors or shapes. Just text.

History in short, in simple words

ASCII grew from teletypes and early computers. In 1963, a first version was agreed on. It helped many different machines talk to each other. With one shared code, a letter like A meant the same number everywhere. This made it easier to send messages and print text.

When ASCII is not enough

ASCII has only 128 items. That is not enough for all languages. It cannot show Chinese, Hindi, Arabic, or many other scripts. It cannot show emoji. It also cannot show many math and music symbols. For these, we use Unicode. Unicode can show many scripts and symbols. UTF-8 is a way to store them. The good news is that all ASCII text works inside UTF-8. So modern systems can read old ASCII easily.

How apps handle ASCII today

Most apps expect UTF-8. But when a file has only ASCII letters and symbols, it looks the same under UTF-8. Programmers like this because it keeps things simple. Web pages, APIs, and many tools use UTF-8, which includes ASCII without changes.

Small number facts and friendly math

ASCII is a 7-bit set. That means up to \(2^7 = 128\) different characters. An extended set with 8 bits has \(2^8 = 256\) items. If your text has only ASCII characters, and it has \(n\) characters, then it uses \(n\) bytes. In a tiny message like OK, \(n = 2\). So it uses 2 bytes when stored as ASCII or UTF-8.

Seeing hidden characters

Some ASCII items do actions and do not print. Space prints blank. But LF and CR move the cursor. TAB jumps. When we open a file in a special editor, it may show LF as \n. That symbol is not part of ASCII itself. It is a way the editor shows the line break to you.

Plain examples that feel real
Things to watch for
How devices use ASCII in simple steps

Imagine a label maker that prints names. It reads the name as characters. It turns each character into ASCII numbers. It stores those numbers in memory. It prints the letters by looking up how to draw each number. If it meets LF (10), it moves to the next line before printing more.

Comparing three ways to write one character’s code

Look at the character '!' again. We can write its code in three ways. Decimal: 33. Binary: 00100001. Hex: 21. In math form, \(\;33_{(10)} = 00100001_{(2)} = 21_{(16)}\). Each form is the same value. Apps pick the form they need. People often read decimal. Computers like binary. Hex is a short way for people to read binary numbers.

Why ASCII lasted so long

ASCII is small and clear. It was made early. Many tools and protocols were built on it. Because the first 128 Unicode codes match ASCII, the plan still works today. This is why you can open very old text files on a new phone or laptop and see the same letters.

Mini walk-through: reading a short file

Open a file with the text Hello. The bytes are the ASCII numbers 72 101 108 108 111. In binary, those are 01001000 01100101 01101100 01101100 01101111. The app reads each number and draws H e l l o on the screen. If the next number is 10, it moves to a new line before drawing more text. This is how simple and steady the process is.

When to choose ASCII-only
Key symbols people often use
Quick check of bit ideas with tiny numbers

Think of the number 10. In binary, that is 00001010. In decimal, it is ten. In ASCII, 10 is LF, the line feed. This shows how the same number can be shown in different ways. The meaning comes from how we use the number. If we say it is a character code, then 10 means LF. If we say it is just a count of apples, then it is ten apples. Context matters.

Bringing it all together with one more example

We will send the word Sun from one device to another. The codes are 'S' 83, 'u' 117, 'n' 110. In binary, 83 is 01010011, 117 is 01110101, 110 is 01101110. The bits travel as On and Off signals. The other device turns bits back into numbers. Then it turns numbers into letters. It shows the word Sun. If the next code is 32, that is a space. If the next is 33, that is '!'. The rules stay the same each time. That is the power of a shared code.

Download Primer to continue