◈ computers mapVol 1 · Ch 01/19
How Computers Work from the transistor up · chapter 01

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.

5V 0V a bare wire, watched over time (no line drawn yet) now 3.20 volts raw voltage swing 0.00 V
restless — the number keeps wandering
no threshold yet — nothing is snapping this to a 1 or a 0. It's just a voltage, and it never holds still.
Fig 1. One dial: noise, the physical world leaking into the wire. There's no threshold here yet — nothing is deciding 1 or 0. It's just a voltage sitting near 3.2 V, and the readout never settles — even at zero it trembles in the last digit, because real wires always do. Crank the dial and the number thrashes. That refusal to hold still is the problem the rest of the chapter exists to solve.

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.

1 territory · “above the line” 0 territory · “below the line” 5V 2.5V 0V a wire 3.4V drag threshold = 2.5 V 1 this wire reads
Grab the gold drag handle (or click anywhere in the panel) to slide the threshold up and down. Everything above it is called 1; everything below is 0.
wire at 3.4 V sits above the line → 1
Fig 2. You stop reading the exact number and just draw a line. Drag the gold threshold up and down: everything above it is declared 1, everything below 0, and the boundary voltage updates live. Slide the wire across the line and watch its meaning flip the instant it crosses — that single decision is what turns a shaky voltage into a definite bit.

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.

2.5 V — the line above → 1 below → 0 5V 2.5 0V raw voltage 4.60 V 1 the clean bit
bit flips (last 1.6 s): 0
rock-solid
Fig. Point the wire high or low and then crank noise to the top: the raw-voltage bar thrashes and its reading never sits still — yet the big 0/1 read off the 2.5 V line barely flinches, and the flip-counter sits at zero. Now hit on the line and add the same noise: the bit starts flickering and the counter climbs. The signal is filthy either way; whether the bit is clean depends only on how far you keep it from the line.

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.

2.5 V — the line 5V 0V the wire, moment by moment → 0 live read last 14 reads
solid 0
Fig 4. Out at the edges the wobble is outvoted — the read never budges. Now hit Park it on the line to sit the mean right at 2.5 V and add noise: the envelope straddles the threshold and the bit thrashes 0-1-0-1, the read a coin-flip. The threshold only buys certainty when the voltage lives far from it; that safe distance is the noise margin, and the whole machine is built on keeping it wide.

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.

5V 2.5 0V the line — 2.5 V above → 1 below → 0 signal 3.8 V the gap 1 the bit margin meter margin wobble
gap 1.3 V · wobble 0.6 V
safe — wobble can't reach the line
Fig 5. The margin is the safe distance between your signal and the line. Aim the signal well above the line to open a wide gap, then raise noise and watch the wobble climb the meter toward the gold margin marker. Predict the moment it cracks: the instant the wobble outgrows the gap, the voltage jumps the line and the bit flips. Shrink the gap and it takes far less noise to break — margin is everything.

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.

5V 0V clean wire 6 one decimal digit 3.20 V
noise 0.00 V · a perfect, silent wire
clean read → 6
ten crisp levels on one wire — more than three times as dense as a bit (log₂10 ≈ 3.3). Tempting, isn't it?
Fig. No noise, no wobble — a perfectly silent wire. Drag the voltage and the 0–5 V range splits into ten clean bands, each reading off one decimal digit 0–9. Every level sits legibly apart, so a single wire could store a whole digit — more than three times denser than a bit, since a decimal digit is log₂10 ≈ 3.3 bits. That is exactly why ten looks tempting; the next figure adds the real world's noise and watches the promise break.

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.

5V 0V 2.80 V noisy wire 5 stored digit fence-hops: 0 recent reads →
the digit holds — 5
Fig. Ten bands split 0–5V into slices just half a volt wide, with nine flimsy fences between them. Park the wire mid-band and it stores a clean 5 — now flip noise on. A wobble smaller than a AA battery's sag shoves the reading across a fence, and the stored digit staggers 4·5·6, lying to you. The fence-hop tally climbs; the truth (green) drowns in errors (red). This is exactly why two levels beat ten: one wide canyon noise can't leap.

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.

5V 2.5 0V 10 thin bands · 9 fragile fences noisy wire 7 stored digit 0 flips / 3s
the digit is lying
Predict first: with the noise untouched, will flipping to two bands steady the read — or not?
Fig 8. Same wire, same noise — only the scheme changes. In ten bands the reading staggers across fences and the flip counter climbs: the digit is lying to you. Flip to two bands and one huge canyon opens between 0 and 1; the identical noise can't leap it, the flip counter drops to zero, and the read goes dead still on a clean bit. Reliability beats density — buy certainty with the gap.

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.

5V 0V the 0–5V wire levels packed as tight as this noise allows levels that survive 7 guard: 0.03 V floor = 2 (binary)
± 0.40 V
7 levels still readable
crank it up: the dial for how many symbols a wire can carry is set by the world, not by you — and it bottoms out at 2.
Fig 9. Before you drag: guess how many levels a really noisy wire can still carry. Now turn noise up. Each level needs a ±noise cushion, so as the world gets louder the cushions swell and fewer levels fit between ground and 5V — the count tumbles from ten toward 2. Binary isn't magic; it's simply the last choice left standing when the noise is at its worst, which is why every machine stops there.

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.

channel SOURCE DRAIN GATE tap each leg to name it
click a leg →
Three legs. Two are the ends of one wire; the third is the lever. Tap each to name it.
named 0 / 3
source and drain are just the two ends of one wire. The gate never touches it — it rules the wire from a distance.
Fig 10. A transistor is just three legs. Two of them — source and drain — are the ends of a single wire that current runs through. The third, the gate, is the lever: a voltage that hovers over the channel and, without ever touching the wire, decides whether it conducts. Name the parts first; watch them act next.

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.

SOURCE 0V DRAIN +5V GATE 0V p‑type silicon n+ S n+ D channel + + + + + PINCHED OFF
channel pinched · no current
Predict first: the source and drain are two islands with a gap between them. What could possibly reach across and bridge that gap — without touching it? Push the gate to 5V.
threshold to open ≈ 1V · a valve for electricity whose handle is electricity.
Fig 11. A MOSFET in cross‑section. The source and drain are two conducting islands with an insulated gap between them — no current can cross. Put a voltage on the gate and its field reaches through the insulator (it never touches the silicon) and pulls a thin layer of electrons up to bridge the gap: the channel forms and the device conducts. Drop the gate to 0V and that layer scatters — the channel pinches shut. A valve for electricity whose handle is itself electricity.

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.

+5V 0V output lamp drain source gate OPEN no current · lamp dark
Before you flip it — will the lamp light?
switch OPEN · lamp dark
the gate is just another wire — set it high and the channel conducts, so current can run the whole loop and do visible work at the lamp.
Fig. A transistor wired to a real load. Set the gate high and its channel conducts, so current runs the entire loop — through the lamp — and it lights; drop the gate to 0V and the channel pinches shut, the loop goes dark, the lamp is off. The switch is now doing visible work, and the lever was only another wire's voltage.

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.

INPUT the gate 0 +5V R pull-up channel 0V (ground) output rail OUTPUT 1 5V · HIGH
in 0 → out 1 · lamp lit
INOUT
01
10
whatever you feed the gate, the output hands back the opposite. That's a NOT gate — one transistor and one resistor.
Fig 13. An inverter — the NOT gate — from one transistor and a pull-up resistor. With the gate low, the switch is open: no path to ground, so the resistor quietly pulls the output up to +5V (out = 1). Drive the gate high and the channel conducts, tying the output down to 0V (out = 0) — and now a steady current runs from +5V through the resistor to ground, which is exactly why holding this NOT gate’s output low costs power. Either way, the output is the opposite of the input.

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.

+5V pull-up R out₁ 5V S1 gate₁ 0V out₁ → gate₂ — just a wire +5V pull-up R S2 gate₂ final output
Predict first: raise gate₁ to 5V — what does out₁ do?
gate₁ (you)0V
out₁ = gate₂5V
final out0V
S1 off · out₁ 5V · S2 conducts · dark
S1's output isn't a lamp — it's a voltage, the same kind of thing a gate eats. So it feeds S2's gate directly. Switches commanding switches.
Fig 14. Two Fig-13 inverters in a row. Stage 1's output is not a light — it's a voltage, the very thing a gate reads. So you wire it straight into stage 2's gate. Raise gate₁ and watch it ripple: S1 conducts → out₁ is dragged down to 0V → that 0V is gate₂ → S2 switches off → stage 2's pull-up lifts out₂ to +5V → the final lamp lights. Nothing here ever pushes a wire up: each transistor only pulls down, and every 1 on this page arrives through a pull-up resistor. Watch the current dots, too — at rest only stage 2 burns current, and raising gate₁ hands that burn to stage 1. One stage at a time. Switches commanding switches — chained a billion times, that is a computer thinking.

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.

+5V pull-up 0V the one wire · one bit gate 5V channel · ON 0V · ground 0 no · off click the gate ↓
gate 5V · channel ON · the channel pulls the wire down to 0V · bit = 0
one wire holds exactly one of two states — and it only holds one because something is actively driving it: the channel down to ground, or the pull-up up to +5V. That single yes-or-no is a bit — the smallest grain of information there is.
Fig. One wire, one bit. The switch here is the transistor from section 3 — no finger touches it; a voltage on the gate is what flips it. Drive the gate to 5V and the channel conducts, pulling the wire down to 0V: the wire reads 0 (no / off). Drop the gate to 0V and the channel opens, so the pull-up resistor lifts the wire to +5V: the wire reads 1 (yes / on). The wire reads the opposite of the gate — that inversion is the NOT you just built. Nothing in between: the wire is driven to +5V or driven to 0V and nowhere else, and that single yes-or-no held on one wire is a bit, the smallest grain of information there is.

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.

your two bits — flip them place 2 place 1 0 0 = 0 the combination · its value the states two bits can hold 00 0 01 1 10 2 11 3 visited 1 of 4 each bit you add doubles the states →
combination 00 — reach all four
Fig. Two switches, and only four places they can land: 00, 01, 10, 11. Flip them until you've lit all four — then add a third bit and watch the count leap to eight. Every bit you add doubles the states, because each old combination splits in two.

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.

Every switch off — the total is 0.
0
= 0
your target 42 — switch on the place-values that add to it
Fig 17. Eight switches, and each one is worth double its right-hand neighbour — 1, 2, 4, 8, 16, 32, 64, 128. Flip any on and its place-value drops into the running sum; the total is just those lit values added up. Chase the target to feel it: there's exactly one set of switches for every number from 0 to 255.

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.

build this number 75
lit place-values add to 0
flip switches to reach the target
Each switch is worth double its right-hand neighbour: 1, 2, 4, 8… up to 128. There is exactly one set of switches that hits any number 0–255.
Fig. A number written in binary is just a choice of which place-values to switch on. The widget names a target; you flip the powers of two — 128, 64, 32…1 — until the lit ones sum to it, and it locks green when they match. Every number from 0 to 255 has exactly one pattern of switches that builds it.

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.

65the number · 0–255
maps to
Athe letter · via ASCII
01000001
64 + 1 = 65 → the byte the machine reads as the letter 'A'
Fig 19. Eight switches, each worth double its neighbour — so one byte counts from 0 to 255. Flip them and the lit place-values sum to a number; then one agreed lookup table, ASCII, turns that number into a character. Set the byte to 65 and it points at A. Nothing about 65 is the letter A — everyone just agreed it would stand in for it.

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.

spins fast ↻ barely turns the byte says 0 00000000
the 1s wheel flips every single step
Fig 20. A byte is one object that counts like a car's odometer. Hit play (or step) and watch the eight wheels roll: the 1s wheel flips on every tick while the 128s wheel barely stirs — it turns just once, at 128. Same clock, wildly different speeds, because each wheel is worth double its neighbour. Eight of them together name every number from 0 to 255.

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.

iolinked.com
Written by Ajai Raj