For years, I’ve coded with high level programming languages like Python, and gotten used to the idea that typing out some text like means a computer will understand what to do and somehow make it happen. This effect has become even more amazing and abstract with the additional layer of AI coding assistants like Claude Code that turn prompts written in natural English into high level code. But how does an inanimate object go from some electrical pulses in silicon to executing commands, performing logic, and following a program structure?
The self-guided course From Nand to Tetris is a great way to learn how and to essentially build each part of the chain that makes up a computer. It is taught in high schools and universities as a CS course but it is also freely available as a 12 module course. Each module teaches the material either as an actual chapter from the book The Elements of Computing Systems, or as a PDF of slides. Then you build that component of the computer, following the assignment and testing your work against the provided source of truth.

Each module is self-contained so you can learn just one topic if that is all you are interested in. Or you can try module #1 and find it so enjoyable that you end up doing every module after that all the way through the end of the course. The course uses the idea of modular design. At first, each module is a black box with a defined interface that you use with the current module You then gradually open each box and learn how to implement that functionality. It’s a useful approach in any type of system engineering.
What worked for me was doing one module per weekend, basically every weekend for 3 months. My goal was to get everything done by Sunday night so I could put everything back on the shelf and be ready for the workweek on Monday. The projects are quite demanding and they dominated my weekends – I’d spend 15-25 hours on each one, which often included some long coding sessions and late nights. Ultimately, though it is incredibly satisfying to figure out all the implementation complexities and end up with something that adds the next layer of intelligence.
The design concepts oftentimes clever and left me with a lot of admiration for the CS pioneers who had the vision and boldness to try turning a bunch of metal, silicon, and electricity into an intelligent machine. There was no guarantee that such a thing was even possible and if one of many links in the chain didn’t work the whole system would have been a dead end.
Now let’s go through each module to see how it works and what the experience was like.
Module 1: Boolean Logic
The starting point of the computer is the NAND gate, a physical device made of transistors, that provides an electrical signal based on 2 inputs. You use a Hardware Description Language (HDL) to define the electrical connections between primitive gates to gradually build up elementary logic gates. This is the way that chips are defined in the industry and it kind of feels like programming as well. A chip is like a function and connecting chips is like passing a variable from into a function. Defining multiple chips as a bigger chip is similar to encapsulating code in a function.
An alternate, more visual way to build chips is NandGame, which implements the same material in this module in a more fun intuitive way.
The key is that any sort of logic you need can be represented by connecting just NAND gates together. If a NAND gate is physically possible, no other gates need to be physically designed or built. The connections between NAND gates provide the intelligence.
The course includes a browser based hardware simulator that allows design of these chips in the browser with the HDL. One of the great things about the course is that almost every module has a source of truth to test against which allows you to identify what part of the design/code is not working and zero in on fixes instead of hoping that the whole design is working. This enables tight iterative cycles, which are great for this sort of development.
Project
Design basic logic gates like the Xor gate or a Multiplexor.

Designing these gates was a good challenge. It was the first step in building a little intelligence into the electronics. For example, stringing together some Not, And, and Or gates randomly wouldn’t do much, but done right, the gate behaves as if one input is a switch that determines whether input A or B will be passed through.
In the hardware simulator, the HDL design of the gate is on the left, the chip input and output states are in the middle, and the test script to compare against truth data is on the right.

Equivalent visual representation:

Module 2: Boolean Arithmetic

Adding 2 Boolean numbers is the foundation of many of the operations a computer performs. This operation can actually be represented as repeating the addition of 3 bits: 1 bit from number A, 1 bit from number B, and 1 bit that carries the overflow from the previous column. So we just have to add 3 bits together using the logic gates from Module 1 and wire them so the carryover bit goes to the right place.

Binary numbers are stored using the “2’s complement” method, which uses half the possible range of values for the negative numbers and half for the positive numbers. It also has very convenient properties. Adding the “2’s complement” representation of a negative number to a positive number can use the same chip design as adding 2 positive numbers together. Flipping the sign of a number (negation) can be done by manipulating bits and subtracting is actually adding the negation of a number. This means that all these operations are just variations on Boolean addition and that a single chip, the Arithmetic Logic Unit (ALU), can do everything.
The ALU applies a function to two 16-bit numbers, with the function defined by several input bits. Basically, doing a combination of addition, bitwise negation, zeroing, or bitwise and results in many useful functions that will be run many times by the machine code in future modules.

Project
Build arithmetic chips that do Boolean addition. Build an ALU.
A portion of the ALU I designed:

For example, the Mux chip uses the selector of zx to choose between either the input of x or an input composed of all zeros. This has the effect of zeroing the input. This is one of the 6 operations that can be strung together to produce a result like output=-1, regardless of what the inputs x and y were.
The tricky part was combining the results of each of the 6 operations so the result at the end reflected the combined function desired, such as x+1.
Module 3: Memory
This module introduces the other primitive gate, the Data Flip-Flop (DFF). The DFF outputs the input value from the previous computer clock cycle. With a DFF, you can build a register that holds a single bit. A RAM unit is composed of thousands of registers with random access addressing logic.

Project
Build a RAM unit using a sequence of registers all the way up to a one that contains 16K registers.
Most of the designs here involved stacking multiple smaller memory units together and then using the demultiplexer and multiplexor to govern which memory unit was written to or read from. The memory addressing works by using a branching structure. For example, in a 6-digit address, the first 3 digits determine which of 8 RAM units to go to. The last 3 digits determine which of the 8 registers in that RAM unit to go to. This results in the register being accessed in a direct path without searching sequentially through all the registers.
A portion of the RAM8 chip:

Module 4: Machine Language
The interface between hardware and software consists of binary machine code which directs the CPU in a series of simple operations: “set the address register equal to 5”, “add the value in the RAM at this address to the value in the data register and store the result in the RAM location”, etc. High level code ultimately becomes machine code with direct electrical control over the CPU.
Symbolic assembly code is one step up from machine code in that it starts to resemble human language, but each line still has a direct translation to binary machine code. Assembly includes the ability to jump to another labeled line in the software if a condition is met, which is how while loops and if statements from the high-level language are implemented. It also adds the concept of variables, which are unique text identifiers that are given a memory location in RAM and can be referenced by the identifier instead of by a numerical address.
There are a limited number of operations that can be performed directly by the CPU so everything else has to be done in terms of that. For example, to determine if x>7 to stop a while loop, you have to jump to a line in the code after the loop only if x-7 is a negative number. Subtracting numbers and determining if a number is negative are efficient hardware operations so comparing two numbers has to be done using those operations.
Project
Write programs in assembly code.
- Multiply 2 numbers from RAM, then store the result in RAM
- When a key on the keyboard is pressed, write a value to every position in memory that corresponds to a black pixel on the screen. When no key is pressed, do the same for a white pixel.
Several examples of other assembly programs were very helpful in understanding how to design the jump conditions. You can write your code in the online IDE and the included assembler will turn it into machine code. The IDE also has a CPU emulator so you can run that machine code on the CPU and see each line execute in real time. The provided test script will run your code and compare the results in memory against the truth values.
A portion of the multiplication program:

Translated into machine code, run on the CPU emulator with 6 test cases, and compared against the correct results:

Module 5: Computer Architecture
The von Neumann architecture allows for software to be loaded into memory like any other kind of data and then to control the CPU. This is what enables a general-purpose computer to do an amazing variety of things all on the same hardware.
The CPU executes instructions in the “Hack” machine language. This is defined as a 16-bit value where each bit means something specific to the CPU. These bits are the electrical signals that flow into the CPU each cycle. The result of this module is hardware that knows how to operate on these 16-bit electrical signals. The goal of all the subsequent modules is to generate those instructions.

The bits in the command determine what registers are used, what part of memory the result is written to, the actual command for the ALU to execute, and what command to load next.
Memory and screen interfaces are defined as what a value in a memory location means relative to a pixel state or a keyboard key press. The total memory consists of RAM, screen, and keyboard sections put together with appropriate addressing logic.
Project
Build a memory chip, a CPU chip, and an overall computer chip from the components in previous modules.
3 test programs are provided and the goal is to design the chips so that when those input commands run in sequence, a useful program actually runs. One of the test programs computes the maximum of 2 numbers, which sounds simple, but watching it happen in real time in the hardware emulator was really cool. You can see the values being written to memory, the operations of the ALU inside the CPU and how the registers are used.
The memory chip actually requires several ALU chips to do arithmetic on the address to determine which part of the memory should be used. The CPU chip was relatively complex and required about 60 lines of HDL code to define.
A portion of the memory chip:

Module 6: Assembler
The assembler parses an assembly command into parts, assigns a binary value to each part, and puts them back together to form a single 16-bit command. The assembler identifies when a variable or label has been declared and then assigns it a value in a symbol table for further reference and replacement. There are also predefined address names such as “ARG” that the assembler replaces with the numerical address “2”.

Project
Write an assembler that translates programs written in the Hack symbolic assembly language into Hack binary machine code.
There are 4 assembly programs provide to test the assembler on. A difficult feature of the assembler is handling symbols so version of the programs are provided without symbols first to get that part running. Then you can implement symbol handling and test on the full program. This incremental approach is provided several times throughout the course and is so helpful to make sure that you don’t get stuck with a task that is too large early on. This is a great way to build momentum and confidence that you are on the right track.
The correct translation into machine code is provided so you can run the text diff (built into the IDE) against your output and iterate on the lines that have been translated incorrectly. This is another great way to keep on track and zero in on problems instead of wondering why the program isn’t executing quite as expected.
Any high-level language can be used to write the assembler – I used Python.
A portion of the assembler implementation:

Part 2
That’s Modules 1-6. Check out Part 2 of this post to see Modules 7-12!