Binary: The Language of Machines
Why computers only speak in 0s and 1s — play with an interactive binary converter.
Every photo you've taken, every message you've sent, every model that's ever answered your question — all of it, at the bottom, is just two symbols: 0 and 1. This lesson explains why computers work this way, how a pile of bits becomes a number, and why this matters for AI.
Why does this exist?
Computers are built from billions of tiny electronic switches (transistors). A switch is reliable at exactly two things: on and off. Voltage high, voltage low. Trying to reliably distinguish ten voltage levels (for decimal digits) is error-prone; distinguishing two is nearly bulletproof. So hardware speaks a two-symbol alphabet — binary — and everything else in computing, including AI, is layered on top of that constraint.
The problem
We have ten fingers, so humans count in base 10: the number 342 means 3 hundreds + 4 tens + 2 ones. Each position is worth ten times the one to its right. But a machine with only two symbols can't have a "tens" place. So how do you write any number using only 0 and 1?
The answer: same trick, smaller base. In binary, each position is worth two times the one to its right. Instead of ones, tens, hundreds — you get ones, twos, fours, eights, sixteens...
How binary counting works
Take the binary number 1011. Reading right to left, the places are worth 1, 2, 4, 8:
place value: 8 4 2 1
digit: 1 0 1 1
contribution: 8 + 0 + 2 + 1 = 11
So 1011 in binary is 11 in decimal. Each digit is called a bit (binary digit). Going the other way — decimal to binary — you repeatedly ask "does the biggest power of 2 fit?":
- Start with 13Find the largest power of 2 that fits into 13. That is 8. Write a 1 in the eights place. Remainder: 13 - 8 = 5.
- Does 4 fit into 5?
- Does 2 fit into 1?
- Does 1 fit into 1?
Try it yourself
Play with the converter below. Suggestions: find the binary for your age. Notice what happens to a binary number when you double it (hint: same trick as multiplying by 10 in decimal). Find the largest number you can write with 8 bits.
32 + 8 + 2 = 42
If you experimented, you found that 8 bits max out at 11111111 = 255. Eight bits is called a byte, and it's the standard unit of computer memory. That's why so many limits in computing are 255 or 256, and why file sizes are measured in bytes.
Bits scale fast
Every bit you add doubles the range. 8 bits give you 256 values; 16 bits, 65,536; 32 bits, about 4.3 billion; 64 bits, about 18 quintillion. This exponential growth is why a handful of bytes can represent any number a program realistically needs.
A code example
Most languages can convert between bases in one line:
# Decimal to binary
bin(13) # '0b1101' (the 0b prefix just means "binary")
# Binary to decimal
int("1101", 2) # 13
# How many values fit in a byte?
2 ** 8 # 256 (0 through 255)
Why AI engineers care
Everything a model touches is bits. The connection to AI is direct:
- Text must become numbers. The next lessons show how characters map to numbers (ASCII/Unicode) and then to bytes (UTF-8). Tokenizers — the front door of every LLM — often operate on those raw bytes.
- Model weights are numbers stored in bits. When you hear that a model was quantized from 16-bit to 4-bit numbers to run faster, that's literally about how many bits store each weight — fewer bits, less precision, smaller and faster model.
- Capacity and cost. Memory, bandwidth, and context are all budgeted in bytes. Intuition for bits is intuition for cost.
Do not memorize — derive
Nobody converts binary in their head at work. What you want is the mental model: positions are powers of 2, n bits hold 2^n values, a byte holds 0–255. Those three facts come up constantly.
Build it yourself
Write a decimal-to-binary converter without using built-ins. The classic method: repeatedly divide by 2 and collect the remainders.
def to_binary(n):
if n == 0:
return "0"
bits = ""
while n > 0:
bits = str(n % 2) + bits # remainder becomes the next bit
n = n // 2
return bits
print(to_binary(13)) # should print 1101
Then extend it: write from_binary(s) that reverses the process, and verify from_binary(to_binary(n)) == n for a few values. Bonus: why does the remainder-collecting trick work? (Hint: dividing by 2 in binary shifts every digit right by one place.)
Summary
- Computers use binary because transistors are two-state switches — it's physics, not preference.
- Binary uses positional notation like decimal, but each place is a power of 2.
- n bits represent 2^n values; a byte (8 bits) holds 0–255 and is the basic unit of memory.
- Everything in AI — text, weights, context — is ultimately bits, and bit-width trade-offs (like quantization) are everyday engineering decisions.