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.
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.
| Decimal | Binary | Place values used |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 10 | 2 + 0 |
| 3 | 11 | 2 + 1 |
| 4 | 100 | 4 + 0 + 0 |
| 5 | 101 | 4 + 0 + 1 |
| 6 | 110 | 4 + 2 + 0 |
| 7 | 111 | 4 + 2 + 1 |
| 8 | 1000 | 8 + 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
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.
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
| Divide | Quotient | Remainder |
|---|---|---|
| 13 ÷ 2 | 6 | 1 |
| 6 ÷ 2 | 3 | 0 |
| 3 ÷ 2 | 1 | 1 |
| 1 ÷ 2 | 0 | 1 |
Read remainders bottom to top → 1101
Binary → Decimal
11
| Bit | Position | Place value (2ⁿ) | Contribution |
|---|---|---|---|
| 1 | 3 | 8 | 8 |
| 0 | 2 | 4 | 0 |
| 1 | 1 | 2 | 2 |
| 1 | 0 | 1 | 1 |
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.
| A | B | Sum | Carry | Note |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | carry 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.
| Character | ASCII value | 8-bit binary |
|---|---|---|
| A | 65 | 01000001 |
| Z | 90 | 01011010 |
| a | 97 | 01100001 |
| z | 122 | 01111010 |
| 0 | 48 | 00110000 |
| 9 | 57 | 00111001 |
| space | 32 | 00100000 |
| ! | 33 | 00100001 |
Text → Binary (ASCII)
| Char | ASCII (decimal) | Binary (8-bit) |
|---|---|---|
| H | 72 | 01001000 |
| e | 101 | 01100101 |
| l | 108 | 01101100 |
| l | 108 | 01101100 |
| o | 111 | 01101111 |
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.
Need a hint? Show decimal values →
| Binary | Decimal |
|---|---|
| 01111001 | 121 |
| 01101111 | 111 |
| 01110101 | 117 |
| 00100000 | 32 |
| 01100100 | 100 |
| 01101001 | 105 |
| 01100100 | 100 |
| 00100000 | 32 |
| 01101001 | 105 |
| 01110100 | 116 |
| 00100001 | 33 |