Wiring the switches
Silicon Almanac All explainers
The chip at work · Explainer 17

From switch to software

Every app on your phone runs on billions of tiny switches, each either on or off. This page climbs from one switch to a running program, one rung at a time.

2transistors in the simplest gate, a NOT
6transistors to hold one bit of cache memory
28 bntransistors in Apple's M4
On is 1, off is 0. Billions: Apple's A14 Bionic, the chip in the iPhone 12 Pro, has 11.8 billion transistors (Apple, 2020). The NOT gate: MIT 6.004. The cache cell: Chenming Hu's textbook and MIT 6.004. The M4: Apple (May 2024). Scene: one transistor cut open, in front of a field of them; schematic, not to scale. Sources are listed at the end.
Scroll to begin
01 · The transistor

A switch with no moving parts.

A transistor of this kind has a source, a drain and a gate, and a fourth terminal, the body (the bulk, in MIT's course), that this page leaves aside. A voltage on the gate pulls a thin layer of electrons up under it, the channel, and the channel joins source and drain: current flows, and the lamp lights. Take the voltage away and the channel goes.

MIT's course puts it in one line: the transistor works as a voltage-controlled switch between source and drain.

Bit
1
Current
Flows
Four terminals and the switch: MIT 6.004 (2017). The gate and its channel: Chenming Hu, Modern Semiconductor Devices for Integrated Circuits, chapter 6 (UC Berkeley). An n-type transistor cut open along its channel and wired to a lamp; sizes are drawn for clarity, not to scale, and the dots stand for electrons. How small the real one is: Wrapping the gate.
02 · Logic gates

Switches that decide.

Wire switches together and they compute. Chips pair two kinds: a p-type that conducts when its gate is 0, and an n-type that conducts when its gate is 1. The p-types join the output to power, the n-types join it to ground, and when one side conducts the other does not. Two transistors make a NOT gate; four make a NAND, whose output is 0 only when both inputs are 1.

NAND alone is enough: any logic function can be built from NAND gates, and MIT's course calls it a universal gate. The Nand to Tetris course builds a working computer from NAND gates and one storage element, a flip-flop, that it takes as given.

Gate
NAND
Output
1
Transistors
4
A lit channel
conducts
Truth table, inputs → output
Pull-up and pull-down: Cornell ECE 2300 (2026) and MIT 6.004. Counts: a gate of this kind with N inputs takes 2N transistors (Tufts COMP 103, 2003); XOR takes 12 as drawn, two inverters and eight, and 6 in a design with transmission gates (Rabaey, Digital Integrated Circuits). Universal gate: MIT 6.004. Nand to Tetris: Noam Nisan and Shimon Schocken. Schematic: each plate names the signal on that transistor's gate; a wire is lit at 1, dark at 0 and grey when nothing drives it.
03 · Arithmetic

Gates that add.

A full adder adds three bits, one from each number and a carry, and gives a sum bit and a carry for the next one. Chain 4 of them and you can add any two numbers from 0 to 15. Each board is one full adder, its 28 transistors lit where their gates switch them on: the input lamps on top, the sum lamp below.

Move A or B and the carry runs from right to left, one adder at a time, and the sum lamps are wrong until it arrives. In a chain like this the wait grows with the number of bits.

A
B
Sum
13 = 01101
Carry out
0
Carry chain
2 stages
Transistors, our arithmetic
4 × 28 = 112

Apple's platforms follow the 64-bit ARM specification apart from a few differences, in Apple's words, and Arm's registers hold 64 bits: 16 times this adder's width (our arithmetic). Courses teach faster designs, such as carry-lookahead, that cut the wait for the carry.

Full adder: Cornell ECE 2300 (2026). 28 transistors: the mirror adder in Tufts COMP 103, lecture 13 (2003), 24 plus 4 in its two output inverters, drawn here in rows with the wiring left out. The wait grows with the bits: Tufts; MIT 6.004. 64 bits: Arm's A64 guide (2024); Apple's developer documentation. Carry-lookahead: Cornell ECE 2300; MIT 6.004. The carry chain is the longest run of adders, one after another, that each hand on a carry; our count. The carry is drawn slowed down.
04 · Remembering

Six switches to hold one bit.

A computer also has to remember. Cache memory on the chip holds each bit in SRAM: 6 transistors, two inverters in a loop that keeps itself on. Main memory holds each bit in DRAM, as charge in a capacitor behind one transistor. MIT's course puts a DRAM cell at about 20 times less area a bit, but the charge leaks, and every cell must be read and written back, a refresh.

Write a bit into both cells. Then switch refresh off and watch the DRAM cell forget.

SRAM cell holds
1
DRAM charge
100%
DRAM cell holds
1
As SRAM, transistors
825 billion
As DRAM, transistors
137 billion

Micron's datasheet for an 8 Gb DDR4 chip requires 8,192 refresh commands within 64 ms, up to 85 °C. Here the leak and the refresh are drawn many times slower.

The cells: Hu, chapter 6; MIT 6.004; SRAM as cache, also Berkeley CS 61C. Refresh: Micron, 8Gb DDR4 SDRAM datasheet (2021). Counts are our arithmetic, cells only: a gigabyte of memory as 2^30 bytes of 8 bits, as JEDEC defines them. As SRAM, 16 GB would take about 825 billion transistors, about 29.5 times Apple's M4 (Apple).
05 · Software

A program is just more bits.

Software is a list of instructions, each a pattern of bits. RISC-V, an open standard, fixes each of its base instructions at 32 bits. This one, add x1, x2, x3, tells the processor to add two of its registers, x2 and x3, which hold the A and B you set above, and to put the answer in a third, x1. Tall cells are 1s.

The fields say what to do: opcode, funct3 and funct7 pick the operation, rs1 and rs2 name the registers read, rd the one written. Pick another operation and only those bits change.

funct7
0000000
rs2
00011
rs1
00010
funct3
000
rd
00001
opcode
0110011
Instruction
add x1, x2, x3
In hexadecimal
0x003100B3
After write back
x1 = 13
Width
32 bits

Fetch: the processor reads the 32-bit word from memory.

Decode: its fields are split out. They name the operation and the registers, which are read.

Execute: the arithmetic logic unit, the ALU, combines x2 and x3.

Write back: the result lands in x1. The next instruction is fetched.

Berkeley's CS 61C names five steps for a RISC-V instruction; the fourth, memory access, loads or stores data, which an add does not, so it is left out here. Apple's iPhones and Macs run Arm's instructions instead, and Arm calls its A64 set fixed-length, 32 bits.

The 32-bit length, the fields and the encodings: RISC-V International, The RISC-V Instruction Set Manual, Volume I (2026); its RV32I registers are 32 bits wide. The 32 bits of add x1, x2, x3 are the ones Berkeley's CS 61C notes work through, and the registers are that example's; the hexadecimal is our arithmetic. The steps: Berkeley CS 61C. Apple: its developer documentation. Arm: its A64 guide (2024).
06 · Scale

Billions of the same trick.

Every rung of this page is built from the one below: adders and memory from gates, gates from switches. A chip runs programs with a great many of them.

Intel's 4004 of 1971, a 4-bit processor that Intel calls the world's first electronically programmable microprocessor, had 2,300 transistors. Apple's M1 had 16 billion in 2020; the M4 has 28 billion. The M3 Ultra joins two M3 Max dies into 184 billion.

On a true scale the M3 Ultra sets the height and every bar is in proportion; every bar up to the 4004 would be far thinner than a pixel, and is drawn as a hairline.

Intel: its timeline (1971). Apple Newsroom: M1 (November 2020), M4 (May 2024), M3 Ultra (March 2025). The first five bars are our arithmetic from the counts above, counting the transistors of each circuit as drawn, cells only for the SRAM. On the power-of-ten scale each line is 1,000 times the one below. Packages drawn, generic.
07 · Where to go next

Now make it fast.

This page climbed from one switch to one instruction. The next one asks how often the switches switch.

Companies on this record that the page names: Apple, Arm, Intel and Micron.

The transistor is the one from the start.