Introduction

A computer is the most layered object most of us will ever use. Press a key and a voltage changes on a wire; somewhere far above, a letter appears in a browser. In between sit a dozen or so layers, each built on the one below it and hiding that one almost completely. We spend our lives at the top of the tower and rarely see down it.

This book climbs the tower from the bottom. It begins with a single switch, a thing that is either on or off, and ends with a web browser fetching and drawing a page. Between those two points every important layer is built in turn: gates, arithmetic, memory, a processor, an assembler, a language, an operating system, a network, and at last the browser. Nothing is taken on faith from above. Each layer is made out of the ones already built, so that by the last page the whole machine has been assembled in front of you, with no magic left inside it.

Theory carries each chapter, but theory alone is easy to half-understand. So every idea here is anchored to a single small program that actually does the thing: a NAND gate built from a switch, a processor that runs a stored program, a router that finds a path, a browser that lays out a page. The programs are written in Python, kept deliberately tiny, and checked by tests, so they are definitely correct. They are the smallest honest model of each idea, not production code. Where a model is too small to be the real thing, the chapter says so plainly: the toy processor has sixteen words of memory, and the secure channel uses numbers small enough to break by hand. The shape is real even when the scale is not.

And one language carries all of it. The same Python that models a single gate also models the processor, the assembler, the network, and the browser, so you never stop to learn a new syntax at each floor; the idea stays in view instead of the machinery. Python earns that job by reading almost like the prose around it: a few dozen lines with no ceremony, no memory to manage and no types to satisfy, little between you and the thing being shown. The cost is paid honestly. A real gate is silicon, a real processor is described in a hardware language like Verilog, a real browser is a million lines of C++; the Python here is never the material a layer is truly built from, only the clearest lens on what that layer does. The idea is the subject, and the language is only how it is held up to the light.

Each chapter asks one question in its title and answers it, in a few pages of prose, a figure or two, and the program itself. A small diagram at the head of each chapter marks how far up the tower you have come. You do not have to run the programs to follow the book, and each is a few dozen lines you can read in one sitting; in the web edition every chapter’s program runs live in the page.

The climb is in four parts. Part I, The Machine, builds a computer from a switch up to a processor that runs programs. Part II, The Software, turns that bare machine into something programmable, with assemblers, languages, and an operating system. Part III, The Network, connects one machine to another, from a single wire up to a private conversation across the world. Part IV, The Browser, sits at the very top and uses everything below it to open a page.

I should say where this book comes from. For years I used computers, and wrote programs for them, without ever seeing how the whole tower fit together; each layer I learned floated free of the ones beneath it, and no single account carried me all the way down. That the entire span could be crossed in one climb is an idea I owe to George Hotz, whose course outline From the Transistor to the Web Browser (github.com/geohot/fromthetransistor) first convinced me it was possible. This book is my own version of that climb, taken slowly and written down.

You need no prior knowledge of how computers work; supplying that is the whole point of the book. A little familiarity with Python will help you read the programs, but the prose stands on its own. Start at the switch, and climb.

Next
✎ Suggest an edit