How computers work

From electrons to hexadecimal, layer by layer

1. What atoms are made of

Electron, proton, and neutron The three subatomic particles that make up an atom: electrons orbit the nucleus while protons and neutrons sit inside it. Electron Charge: −1 Orbits the nucleus Tiny — almost no mass + Proton Charge: +1 In the nucleus Defines the element 0 Neutron Charge: 0 In the nucleus Adds mass and stability

Everything you can touch — copper wire, silicon chips, air, water, your own hand — is made of atoms. And every atom is made of just three kinds of particles.

Electron — tiny, negatively charged, orbits around the outside of the atom. Almost no mass. This is the particle that does all the work in electricity and electronics. Remember this one — every animation after this is really about electrons.

Proton — positively charged, sits in the nucleus at the center of the atom. The number of protons is what makes an element what it is: 1 proton = hydrogen, 29 = copper, 79 = gold. Change the proton count and you literally change what element you're looking at.

Neutron — no charge. Also sits in the nucleus alongside the protons. Adds mass and keeps the protons from flying apart from their mutual repulsion.

Positive and negative charges attract. Same charges repel. That single rule drives everything that follows.

2. How they're arranged in an atom

Atom with valence electrons A nucleus surrounded by an inner electron shell and an outer valence shell. The outer valence electrons are loosely bound and are the ones that flow in a conductor. + e− e− e− e− Inner electrons Tightly held Valence electrons Outer shell, loosely bound These can hop atom to atom Nucleus Protons + neutrons (positive)

Zoom out one level. In a normal atom, the protons and neutrons cluster in the nucleus. The electrons orbit around the nucleus in shells — like layers of an onion.

Inner shell electrons sit close to the nucleus and are held tightly — they're not going anywhere.

But the outer shell — called the valence shell — is loose. Those electrons are barely hanging on. Give them a little push and they'll hop right off to a neighboring atom.

This is the whole game. Materials that hold their valence electrons tight (rubber, glass, plastic) are insulators. Materials with loose, practically-free valence electrons (copper, silver, gold, aluminum) are conductors. Everything electrical exists on this spectrum.

From here on, when I say "electron," I mean a valence electron. The inner ones don't matter for our purposes.

3. Putting those electrons to work

Electron flow in a basic circuit A battery's negative terminal repels electrons through a wire to the positive terminal, which attracts them. + Repels electrons Attracts electrons e− e− e− e− e− e−

Take a conductor — copper wire is the classic example. Now hook it up to a battery. The battery has two terminals: negative (−) and positive (+).

The negative terminal is packed with extra electrons. Because negative charges repel each other, they're pushing against each other trying to get out. The positive terminal is the opposite — it's short on electrons, so it pulls them in.

Give the electrons a path (the wire), and they flow. Negative terminal to positive terminal, through everything in between, until the pressure equalizes or the battery runs down.

That flow is what we call current. Every electrical device — light bulbs, motors, phones, computers — is just something you put in the middle of that flow to make it do useful work.

Textbook footnote: Old physics diagrams draw current going the opposite direction, positive to negative. That's a leftover from before we knew electrons were the ones actually moving. The physical reality is what you see here.

4. What flow actually looks like

Electron hopping between atoms An electron leaves the valence shell of one atom and joins the valence shell of an adjacent atom, illustrating the basic mechanism of current in a conductor. + + e− Atom A Atom B

Here's where most people get tripped up. Electrons don't stream through the wire like water through a pipe. That's not what's happening.

What's actually happening: each electron only moves a tiny distance before it settles into the valence shell of the next atom over — and kicks THAT atom's outer electron off in the process. Then that displaced electron does the same thing to the atom next to it. And so on, down the wire.

It's a chain reaction of hops. The electron that arrives at the far end isn't the same one that started. They're being handed off, atom by atom.

The signal (the "current") travels close to the speed of light because the chain reaction propagates almost instantly. But any individual electron moves at a crawl.

Think of a stadium wave — the wave shoots around the stadium in seconds, but any one person just stands up and sits down.

5. Measuring what's happening

Electrical measurements: voltage, amperage, resistance The three basic electrical measurements demonstrated on a simple circuit. Voltage is the pressure pushing electrons, amperage is how many electrons pass a point per second, and resistance is how much the path restricts flow. + Voltage (V) Pressure pushing electrons forward Amperage (A) Electrons flowing past a point per second Resistance (Ω) How much the path restricts the flow Ohm's law ties them together: V = I × R

Now that we've got flow, we need a way to talk about it. Three measurements describe any electrical circuit — and they're locked together by a single equation.

Voltage (V) — the pressure. How hard the electrons are being pushed. A 9-volt battery pushes with 9 volts of force. A wall outlet pushes with 120. Voltage is measured between two points — you can't have voltage at just one place.

Amperage (A) — the flow rate. How many electrons are passing a given point per second. More amps = more electrons per second.

Resistance (Ω, "ohms") — how much the material fights the flow. Copper wire has near-zero resistance (electrons pass easily). A heater coil has high resistance (electrons have to fight to get through). Glass has near-infinite resistance (nothing gets through).

They tie together as V = I × R — Ohm's law. Change any one and the others adjust. This equation is the entire foundation of practical electrical work: every wire gauge chart, every circuit breaker rating, every battery spec — it's all Ohm's law in different clothes.

6. What electron flow can DO

Four kinds of work flowing electrons can do Electrons in a circuit can dissipate as heat, emit photons as light, generate magnetic fields, or control other electron flow through transistors. Heat Resistance dissipates energy Heaters, filaments Light Electrons emit photons LEDs, screens, lamps N S Magnetism Moving electrons make fields Motors, speakers, generators T control Control Small input gates current Transistors, switching

Once you've got electrons moving through a circuit, you can turn that flow into four kinds of useful work. These four are the entire menu of what electricity is for.

Heat — force electrons through something with high resistance and the friction dissipates as heat. This is your space heater, your toaster, an old-school incandescent light bulb (a filament that got so hot it glowed), the burner on a kitchen stove. Ohm's law explains why: high R means the current has to fight, and that fight becomes thermal energy.

Light — in LEDs and other semiconductors, electrons drop energy levels and release the difference as photons. Every screen you look at is doing this — billions of tiny LEDs turning on and off.

Magnetism — any moving electric charge generates a magnetic field. Coil a wire around something, run current through it, and you have an electromagnet. That's how motors, speakers, generators, transformers, and the read head of a hard drive all work.

Control — this is the one that matters most for computers. A small amount of current can be used to gate a much larger amount. That's a transistor. That's how we get from raw electricity to logic and computation. The rest of this series is following that fourth branch.

7. Making a controllable material: doping

Semiconductor doping creates N-type and P-type silicon Pure silicon has 4 valence electrons per atom, all bonded. Doping with phosphorus (5 valence electrons) creates N-type silicon with a free extra electron. Doping with boron (3 valence electrons) creates P-type silicon with a hole, a missing electron that behaves as a positive charge carrier. Pure silicon Si Si Si Si Si Each Si shares 4 electrons with 4 neighbors No carriers N-type P Si Si Si Si e− Phosphorus has 5 valence electrons → one extra, free to flow Negative carriers P-type B Si Si Si Si + Boron has 3 valence electrons → one missing, leaves a hole Positive carriers Sandwich the layers N-P-N or P-N-P → transistor

To build an electronic switch, you need a material where you can decide, moment to moment, whether electrons can flow through it or not. Pure silicon almost works — but not quite.

Silicon has 4 valence electrons per atom. In a pure silicon crystal, every atom bonds neatly with 4 neighbors, and every electron is locked into a bond. No loose electrons to carry current, no empty spots to accept new ones. It just sits there — no carriers, no conduction.

Doping is the trick that fixes this. You deliberately mix in a tiny amount of a different element to create carriers on purpose.

N-type silicon — add phosphorus (5 valence electrons). Four bond into the silicon lattice; the fifth is left over, free to wander. You now have extra electrons that carry current. Negative carriers — that's where the N comes from.

P-type silicon — add boron (3 valence electrons). Now there's one missing bond — a hole. A neighboring electron can hop into that hole, which effectively moves the hole in the opposite direction. Holes act as positive carriers — that's the P.

Neither type is very useful on its own. But sandwich them together — N-P-N or P-N-P — and you've built a transistor.

8. The transistor: an electronic switch

Transistor as an electronic switch A transistor uses a small control signal to switch a larger current on or off. When control equals 1, current flows; when control equals 0, current is blocked. In Out transistor 0 1 control An electronic switch with no moving parts Voltage on control (1) → current flows No voltage on control (0) → current blocked

Take a doped-silicon sandwich (NPN or PNP), attach three wires — input, output, and control — and you've built a switch with no moving parts.

Here's how it works: put voltage on the control pin and the middle layer's electric field lets carriers cross. Electrons flow freely from input to output. Take the voltage off the control pin and the field collapses — the path closes and current is blocked.

Before transistors, computers used mechanical switches called relays. Physical arms that flicked open and closed. Slow, huge, prone to failure, and drew a ton of power. The first digital computer (ENIAC, 1945) used 17,000 vacuum tubes and filled a room; it was constantly breaking down.

Transistors do the same job but they're solid-state — nothing physically moves. They switch billions of times per second and you can pack billions of them into a chip the size of a fingernail. A modern smartphone has more transistors than there are stars in the Milky Way.

Everything from here on is just lots and lots of transistors, arranged in patterns.

9. Two flavors: NPN and PNP

NPN and PNP transistors NPN transistors conduct when control is high (1). PNP transistors conduct when control is low (0). Their complementary behavior is the basis of binary logic gates. NPN V+ 1 0 control Active high Conducts when control = 1 PNP V+ 1 0 control Active low Conducts when control = 0

Because a transistor is a sandwich, there are two ways to stack the layers.

NPN conducts when the control pin is HIGH (voltage present, "1"). "Active high."

PNP conducts when the control pin is LOW (no voltage, "0"). "Active low."

They're mirror images of each other. Neither is "better" — they're complements.

Why does that matter? Because if you pair them up — one NPN and one PNP sharing the same control signal — exactly one of them is on at any given moment. Never both, never neither. That pairing is called CMOS (complementary metal-oxide semiconductor), and it's what every modern chip is built out of. Efficient, low-power, and it scales down to features just a few atoms wide.

The little arrow on the emitter (the bottom leg in each diagram) is how you tell them apart on a schematic — arrow pointing OUT of the transistor is NPN, arrow pointing IN is PNP. Not something you memorize, just something to recognize.

10. From switches to numbers: binary

Binary: bits and bytes (smallest value first) One bit is 0 or 1. Eight bits make a byte. Each position represents a power of 2, doubling from left to right: 1, 2, 4, 8, 16, 32, 64, 128. With bit 0 (value 1) and bit 6 (value 64) active, the byte equals 1 plus 64, which is 65. In ASCII, 65 is the letter A. 1 byte = 8 bits 1 0 0 0 0 0 1 0 1 2 4 8 16 32 64 128 1 + 64 = 65 1 byte → 256 possible values (0 to 255) 65 in ASCII = the letter "A"

A transistor is either on (current flowing) or off (current blocked). Two states. That's it — no in-between.

We call each transistor's state a bit: a single 0 or 1. This is the fundamental unit of everything a computer does. Every photo, every video, every song, every AI model, every text message — all of it is millions or billions of transistors, each in one of two states.

One bit isn't much. But group 8 bits together and you get a byte. Each position in the byte represents a power of 2 — the values double as you move across: 1, 2, 4, 8, 16, 32, 64, 128. Turn on the bits you want, add up their place values, and you have a number.

The byte shown here — 10000010 reading left to right — has the 1-bit and the 64-bit turned on. 1 + 64 = 65. And in ASCII (the standard mapping of numbers to text characters), the number 65 represents the letter "A". Same byte, three different ways of reading it: bits, decimal number, character.

Convention note: This diagram reads smallest-value-first (left to right) because it's easier to teach that way. Standard binary notation is written the other way around — biggest value first — so 65 would normally appear as 01000001. Same byte, mirrored. Both are correct.

11. Watching binary count

Counting from 1 to 8 in binary An animated demonstration of binary counting from 1 to 8. Each decimal number is built by activating the right combination of bits with place values 1, 2, 4, and 8. Counting 1 to 8 in binary 1 0 1 0 1 0 1 0 0 0 0 0 1 2 4 8 16 32 64 128 1 2 3 4 5 6 7 8 1 = 1 2 = 2 1 + 2 = 3 4 = 4 1 + 4 = 5 2 + 4 = 6 1 + 2 + 4 = 7 8 = 8

Same 8-bit byte, but now animated — counting from 1 up to 8. Only the first four bits change because we're not counting high enough to need the rest.

Notice the pattern: 1 = just the 1-bit. 2 = just the 2-bit. 3 = both the 1-bit AND the 2-bit (1 + 2 = 3). 4 = just the 4-bit. 5 = the 4-bit and the 1-bit (4 + 1 = 5). And so on.

Every whole number can be expressed as a specific combination of these place values turned on. That's binary — a number system that uses only 0s and 1s, perfect for a machine whose fundamental unit is on/off.

Bigger numbers just need more bits. 8 bits gets you 0 to 255. 16 bits gets you 0 to 65,535. 32 bits gets you into the billions. 64 bits — what most modern chips work with — gets you into numbers so large they're used to count grains of sand in the Sahara without breaking a sweat.

12. Turning transistors into logic

The common logic gates Six logic gates that build every digital circuit. AND outputs 1 when both inputs are 1. OR outputs 1 when either input is 1. NOT inverts its single input. NAND and NOR are inverted versions of AND and OR. XOR outputs 1 only when the two inputs differ. AND 1 if both inputs = 1 OR 1 if either input = 1 NOT Inverts the input NAND 0 if both inputs = 1 NOR 0 if either input = 1 XOR 1 if inputs differ Every digital circuit — adders, memory, CPUs — is built from these gates

Now we're going to wire multiple transistors together to make circuits that take bits IN and produce a bit OUT — based on a rule. These are called logic gates. Six of them cover almost everything.

AND — outputs 1 only if BOTH inputs are 1. Like two switches wired in series — both have to be on for the current to reach the other side.

OR — outputs 1 if EITHER input is 1. Two switches wired in parallel — just one needs to be on.

NOT — takes one input, flips it. 1 becomes 0, 0 becomes 1.

NAND and NOR — inverted versions of AND and OR (that little circle on the output is the "not" bubble).

XOR ("exclusive or") — outputs 1 only when the inputs are DIFFERENT. Same inputs → 0. This one is subtle but incredibly useful.

Wild fact: NAND alone is enough to build every other gate. Same with NOR. They're called "universal gates" — with enough of just one type, you can construct any digital circuit that has ever existed. Most chip fabs actually build almost exclusively out of NAND-based CMOS pairs and derive everything else from combinations.

13. Doing math with gates: the half-adder

Half-adder: stringing logic gates to do binary math Two bits A and B feed into an XOR gate and an AND gate in parallel. The XOR output is the Sum bit, the AND output is the Carry bit. This is 1-bit binary addition. The animation cycles through 0+0=0, 0+1=1, 1+0=1, and 1+1=2 (binary 10). Half-adder: 1-bit addition with XOR + AND A 1 0 B 1 0 XOR AND 1 0 Sum 1 0 Carry 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 2 Output reads as a 2-bit binary number: Carry × 2 + Sum × 1

Now for the payoff. Wire two logic gates together — an XOR and an AND — and you can actually do arithmetic with bits.

Feed in two 1-bit inputs (A and B). You get two output bits (Sum and Carry):

XOR produces the Sum bit — outputs 1 when the inputs differ. Because in binary: 0+1 = 1 and 1+0 = 1, but 0+0 = 0 and 1+1 = 0 (with a carry to the next column).

AND produces the Carry bit — outputs 1 only when both inputs are 1. Because that's the only case where the addition overflows past a single bit.

Read the outputs together as a 2-bit binary number and you've literally done 1-bit addition. 1 + 1 = 10 in binary = 2 in decimal.

This is called a half-adder because it only handles one column of addition. A full adder adds a third "carry-in" input so you can chain them together — column-by-column, exactly like doing long addition on paper. Chain 8 full adders and you can add two bytes. Chain 64 of them and you have the integer adder inside a modern CPU.

From here, it's the whole computer. Adders go into the ALU (arithmetic logic unit). Latch a few thousand more gates together to build registers and memory. Add a clock and a control unit, and you're executing instructions. Every word doc, every video, every AI model — all of it eventually decomposes into voltages running through transistors arranged into gates. That's it. That's the whole magic trick.

14. Reading binary the compact way: hex

Binary to hexadecimal conversion An 8-bit byte converts to a 2-digit hexadecimal number. Each nibble (4 bits) maps to one hex digit from 0 to F. Binary → hexadecimal upper 4 bits lower 4 bits Each 4 bits → 1 hex character (0–9, A–F = 0–15) 0 0 0 0 1 1 1 1 0 F 0x0F (15 in decimal) 1 1 1 1 0 0 0 0 F 0 0xF0 (240 in decimal) 1 1 1 1 1 1 1 1 F F 0xFF (255 in decimal) 1 1 0 0 1 0 1 0 C A 0xCA (202 in decimal)

One last piece — because reading raw binary is exhausting. Try scanning 11011010 01101001 10101010 at a glance without going cross-eyed. Nobody actually reads bytes this way.

The trick: 4 bits has exactly 16 possible values (0 through 15). And there's a numbering system with exactly 16 characters — hexadecimal, or hex. It uses 0 through 9, then A through F (for values 10 through 15). So 4 bits maps perfectly to one hex character. A whole byte (8 bits) fits in just 2 hex characters.

Split the byte down the middle. Upper 4 bits → first hex character. Lower 4 bits → second hex character. Prefix it with 0x to make it clear you're reading hex, not decimal.

You'll see hex all over the place once you know what to look for:

  • Color codes#FF0000 is red. That's three bytes: FF (255) red, 00 (0) green, 00 (0) blue. Every color on every screen is just three hex bytes.
  • Memory addresses0x7FFE3A4C. Every location in your computer's RAM has one.
  • ASCII characters'A' = 0x41. Same as decimal 65, same as binary 01000001. Three ways of writing the same byte.
  • File signatures — the first few bytes of a file usually identify its type. 0xFFD8FF = JPEG. 0x89504E47 = PNG.
  • MAC addresses, cryptographic hashes, encryption keys — anywhere you need to display large amounts of raw binary without going insane.

And that's the whole stack. Voltage in a wire → electrons in a conductor → doped silicon → transistors → logic gates → binary → hex → programs → applications → the entire digital world. Every layer sits directly on top of the one below it, and none of it is magic.

^ Top