01The Switch
Everyone says a computer is "just ones and zeros." That sentence is a tiny lie, and it hides the best part. A wire doesn't hold a 1 or a 0. It holds a voltage — a real electrical pressure. That pressure sags when the battery tires. It spikes when a motor kicks on next door. And it jitters constantly from the warm, noisy chaos of the physical world. So here's the question this whole chapter turns on, the one most tutorials skip: how do you get a rock-solid yes-or-no out of something as shaky as electricity? Answer that, and you've found the atom of computing — a switch that another wire can flip. We'll build it in your hands, one small step at a time. We'll wobble a voltage, drop a line through it, meet the transistor at the metal, then pack eight of these switches into a byte that counts and spells. There's no magic in any of it. It's just electricity doing exactly what we corner it into doing.
01The wobble, and the line that cleans it
Picture a single wire running out of a battery. We'd like it to mean something — say, on or off. But put a fast enough meter on it and you'll never see a clean number. You'll see a voltage that trembles: 3.1 volts, then 3.3, then a dip to 2.9 when the fan spins up, then a little spike when something switches across the room. Before we do anything clever with it, just look at the raw thing for a moment. Grab the noise dial and turn it up. This is the actual wire, wandering.
That trembling is noise. It is not a defect you can engineer away. It's the physical world leaking into your circuit. If a computer had to read an exact voltage to know what you meant, it would be wrong constantly. So notice the trap we're in. The number never sits still, yet we need a stone-cold answer out of it.
Here's the move, and it's almost insultingly simple. We stop trying to read the exact voltage. Instead we draw one line — a threshold — straight across the range. Then we make a single ruthless rule: anything above the line means one thing, anything below it means the other. Drag the line up and down below. Watch the wire's range split into two territories — a 1 country up top, a 0 country underneath.
See what we just bought? We threw away the exact value on purpose. We kept only the answer to one question — which side of the line? That yes/no is the thing this whole book is made of, so let's use its name from here: it's a bit. That's the whole idea of a threshold. It's a cheap, brutal decision that turns a shaky measurement into a clean verdict.
Now let the two ideas meet. Put the trembling voltage and the fixed line in the same picture, then read the bit off the top. Crank the noise all the way up. Watch the raw voltage thrash while the clean bit underneath sits there, unmoved.
The signal is filthy; the bit is pristine. That is the trick the entire machine is built on. Not clean electricity, but a decision cheap enough to run a billion times a second. That decision manufactures certainty out of a mess.
But there's a catch, and it's worth feeling in your hands rather than being told. The trick only works when the voltage sits far from the line. Slide the signal so it parks right on the threshold, then add a breath of noise. Watch the bit start to flicker, flipping 0-1-0-1 as the wobble tips it back and forth across the edge.
So the line alone isn't enough. What matters is where you aim the voltage relative to the line — that's the whole game. Out at the edges there's a wide, safe gap between where the signal sits and where the line is. That gap has a name: the noise margin. As long as the wobble stays smaller than the margin, the answer physically cannot change. Set a signal level below and watch how much noise the margin can absorb before the bit finally cracks.
That's the real deal a bit strikes. Keep the signal far from the line, and noise is simply outvoted. That raises a sharp question. If a fat margin is what keeps us safe, how many different symbols can we actually afford to pack onto one wire?
02Why two symbols, not ten
Here's the natural objection, and it's a good one. Our wire swings a full 5 volts. Why waste all that range on a measly two symbols? We could slice 0–5V into ten bands and store a whole decimal digit on a single wire — 0 through 9. That's more than three times as much information on one wire — a decimal digit is log₂10 ≈ 3.3 bits. And on a clean wire, that works perfectly. Drag the voltage below and read the digit off. Ten crisp levels, each one legible.
On paper it looks like free money. Ten symbols per wire instead of two — who would ever choose two? So before I answer, let's do the honest thing and put that scheme in front of the real world.
Same ten bands, same wire — now turn on the noise. Watch the digit you're "storing" stagger between 4 and 5 and 6, hopping fences every time the voltage twitches. It isn't holding a value anymore. It's lying to you.
The bands are only half a volt apart, so the fences between them are flimsy. The tiniest nudge hops one and corrupts your data. Now keep that exact same noise and collapse the scheme down to two levels. Watch what happens to the read.
Dead still. Two levels leave one enormous canyon between 0 and 1, and noise would have to be violent to leap it. So the trade-off isn't really "two versus ten." It's a dial, and the world sets where you can stop. Turn up the noise below and watch how many levels can still survive it.
And now the objection collapses cleanly. Computers chose binary not because two is mathematically special, but because it's the most defensible choice. Its margin is so wide that ordinary noise can't touch it. Every bit you'll ever meet is this bargain: give up density, buy certainty.
One honest note before we move on, because some of you already know the counterexample. Engineers really do pack more levels onto a wire. The flash memory in your phone stores four, eight, even sixteen levels in a single cell, and the fastest links between chips send four. That isn't the rule breaking. That's the rule spending a different budget: those paths are short, quiet, and wrapped in error correction that catches the misreads. A logic wire gets the worst budget there is — long, loud, chained a billion deep, with nothing downstream to catch a mistake. So on a logic wire, the count falls all the way to two.
03The switch that electricity flips
We can read a bit off a wire now. But reading isn't computing. To compute, one wire's answer has to be able to change another wire's. We need a switch. Not a switch your finger flips, but a switch that electricity itself flips. That device is the transistor, the single most important object in this entire book. So let's meet it honestly, at the metal. It has exactly three legs. Click each one below and see what it's for.
Two of the legs — source and drain — are the ends of a wire that current wants to flow through. The third leg, the gate, is the lever. But the lever isn't mechanical. It's just another voltage. Put a high voltage on the gate and it opens a conducting channel between source and drain. Drop the gate to zero and the channel pinches shut. Toggle the gate below and watch the channel open and close.
But hold on to the two words we just used: high and low. Back at the start, those meant one thing only — which side of a line we drew. The transistor has never seen our diagram. So don't toggle the gate this time. Raise it slowly from zero and watch. Nothing. Still nothing. Then, at one particular voltage, the channel appears and current runs. (There's a whisper of current below that point, far too small to matter to us.) That voltage is the transistor's own threshold voltage, and it is section 1's move made out of atoms — the transistor draws its own line, at its own voltage, not at the 2.5 V we picked. Nobody draws that line. The transistor is the drawing.
That's the heart of it: a valve for electricity whose handle is electricity. Now let's make it do visible work. Wire the channel to a load — a little lamp — so current has somewhere to go. And current only flows around a complete loop: out of the +5V supply, through the lamp and the channel, and back to where it started. That return path has a name — ground, the 0V floor we measure everything against. Flip the gate and watch current run the path and light the lamp.
A switch you never touch — the gate voltage throws it for you. And here's the first genuinely surprising thing you can build from exactly one transistor. But the transistor can only ever pull a wire down, to ground. So where does a high output come from? From one more part — a resistor: a weak path up to +5V, always tugging, easy to overpower. Wire it so the output sits high when the gate is low, and low when the gate is high. Gate low: no path down, the weak tug wins, out sits at +5V. Gate high: the channel opens a strong path to ground, the tug loses, out is pinned to 0V. You've made an inverter — a NOT. Whatever you put in, it hands you back the opposite. Toggle the input and watch the output flip against it.
| IN | OUT | |
|---|---|---|
| 0 | → | 1 |
| 1 | → | 0 |
Sit with the deepest fact here, because it's the hinge the whole field swings on. The thing that flips the switch is the same kind of thing the switch controls — a voltage in, a voltage out. So the output of one transistor can be wired straight to the gate of the next. Flip the first gate below and watch the signal march through both.
Switches that command switches. That is the instant a pile of inert silicon becomes able to decide. And deciding, chained a billion times, is all a computer ever does. But before we chain them into logic, let's give the thing they're passing around its proper name.
04Naming it: the bit and the byte
We named this back at the line: our hard-won yes/no is a bit, short for binary digit — the smallest grain of information there is. Here it is on its own. One wire, holding one of two states. Click the switch below. That flip, on to off, is one bit changing its mind.
One bit alone is nearly mute. It can say yes or no and nothing more. But watch what happens the moment you set two of them side by side: the combinations multiply. Toggle both bits below and count the distinct states you can make.
Two bits give you four states, three give you eight. Every bit you add doubles the count. You've read numbers this way since you were six: 407 is 4 hundreds, 0 tens, 7 ones. Binary is that same machine, running on the doubling you just watched. Each new bit doubles the states, so it must be able to name more numbers than all the old bits together. 1, 2 and 4 only reach 7, so the next place has to be 8. So every bit position has a place value: 1, 2, 4, 8, 16, 32, 64, 128, doubling as you go. Nothing physical picks eight — it's a convention that stuck, wide enough to hold a character. A switched-on bit simply adds its place value to the total. Click the bits below and watch the lit ones sum.
And now something falls out for free, which is my favourite kind of fact. Because 1, 2 and 4 only reach 7, the 8 place outweighs everything beneath it put together. That holds at every place: 128 beats 1+2+4+8+16+32+64, which is 127. So build a number from the top down. Take the biggest place that still fits, then the next, and you can never overshoot. You can never tie either, because the small places added up can never reach a big one. One number, one pattern. Always. Nobody decreed that — the doubling forced it.
Same machine as decimal, then — only our places double instead of multiplying by ten. Now flip it around and use that top-down trick. Instead of reading whatever comes out, aim for a specific number. Try to hit the target below by switching on the right places.
That's you writing a number in binary, bit by bit. Eight bits together is a byte, and a byte can name any number from 0 to 255. But numbers can stand in for other things too. Agree on a table that maps each number to a character, and a byte becomes a letter. That table is ASCII. Set the byte below and watch the number turn into text.
The number 65 is the byte the machine reads as the letter A — not because 65 is A, but because we all agreed it would be. And to feel a byte as one whole object, rather than eight loose switches, watch it count. Hit play and let it tick from 0 to 255. Watch the low bit blur while the high bit barely moves — an odometer made of switches.
And that's Chapter 1. You built the bit from the ground up. You wobbled a voltage and cleaned it with one line. You saw why two symbols beat ten. You met the transistor that lets electricity throw its own switch. And you packed eight bits into a byte that counts and spells. But notice we've only ever made switches hold and pass along a value. The magic starts when switches act on each other — when the output of one decides the input of the next in a way that reasons: if this and that, then…. That device is a logic gate. Building the first one out of nothing but the switch you just met is where we go next.