← Back to modules

Module

Binary

The foundation of how modern computers store and process everything from integers to images to AI predictions.

1. What is binary

What is binary?

Binary is a base-2 number system it uses exactly two digits: 0 and 1. The word comes from the Latin binarius, meaning “consisting of two.”

You already know the decimal system (base 10): digits 0-9, and each position is worth ten times the one to its right. Binary works the same way, but with only two digits and each position is worth twice the one to its right.

Why do computers use binary?
Computers are built from billions of transistors tiny electronic switches that are either on (1) or off (0). It is far easier and more reliable to build hardware that distinguishes two states than ten. Binary is not just a convention; it is the natural language of electronics.

2. Counting in binary

Counting in binary

In decimal, when you run out of digits in a column you carry over to the next column (9 → 10). Binary works identically, but you carry after 1.

DecimalBinaryPlace values used
000
111
2102 + 0
3112 + 1
41004 + 0 + 0
51014 + 0 + 1
61104 + 2 + 0
71114 + 2 + 1
810008 + 0 + 0 + 0

Notice that powers of 2 (1, 2, 4, 8, 16, …) always start with a 1 followed entirely by zeros just like powers of 10 do in decimal.

Place values in binary

12827
6426
3225
1624
823
422
221
120

3. Conversions

Converting between binary and decimal

Binary → Decimal: Multiply each bit by its place value (a power of 2), then add all the results together.

Decimal → Binary: Repeatedly divide the number by 2. Each remainder (0 or 1) becomes a bit. Read the remainders from bottom to top.

Example 13 to binary:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read bottom to top: 1101
Check: 8 + 4 + 0 + 1 = 13

Decimal → Binary

1101

DivideQuotientRemainder
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Read remainders bottom to top → 1101

Binary → Decimal

11

BitPositionPlace value (2ⁿ)Contribution
1388
0240
1122
1011

Sum of contributions = 11


4. Arithmetic

Arithmetic in binary

Binary arithmetic follows the same rules as decimal arithmetic the only difference is that you carry after 1, not after 9.

ABSumCarryNote
0000
0110
1010
1101carry the 1 → next column

Example: 5 + 3 in binary

Decimal

  5

+ 3

= 8

Binary

 101

+011

1000

Column 1: 1+1=10 → write 0, carry 1

Column 2: 0+1+1=10 → write 0, carry 1

Column 3: 1+0+1=10 → write 0, carry 1

Column 4: 0+0+1=1 → write 1

This same addition logic is what happens inside your CPU billions of times per second. Every calculation your computer makes from rendering a pixel to running a machine-learning model ultimately reduces to binary arithmetic.

Try it: add two binary numbers

Enter two binary numbers (up to 8 bits each) and see the column-by-column addition with carries.

+

5. ASCII encoding

Encoding text with binary (ASCII)

Numbers are straightforward to store in binary. But what about text? Computers handle this by assigning every character a number, then storing that number in binary.

ASCII (American Standard Code for Information Interchange) is one of the oldest character encodings. It maps 128 characters letters, digits, punctuation, spaces to integers 0-127. Each character only needs 7 bits, though computers typically use 8 bits (one byte) per character and leave the leading bit as 0.

CharacterASCII value8-bit binary
A6501000001
Z9001011010
a9701100001
z12201111010
04800110000
95700111001
space3200100000
!3300100001

Text → Binary (ASCII)

CharASCII (decimal)Binary (8-bit)
H7201001000
e10101100101
l10801101100
l10801101100
o11101101111

Guided Project

Put it all together

Below is a message encoded entirely in binary. Use everything you've learned in this module conversions, place values, ASCII to decode it. Take your time; there are 11 characters.

Guided Project: Decode the Message

Each group of 8 bits below represents one ASCII character. Convert each group to decimal, then look up (or recall) the matching character. Type the decoded message in the box when you're ready.

01111001char 1
01101111char 2
01110101char 3
00100000char 4
01100100char 5
01101001char 6
01100100char 7
00100000char 8
01101001char 9
01110100char 10
00100001char 11
Need a hint? Show decimal values →
BinaryDecimal
01111001121
01101111111
01110101117
0010000032
01100100100
01101001105
01100100100
0010000032
01101001105
01110100116
0010000133