How to learn logic gates, step by step
Logic gates are the building blocks of every computer. The good news: there are only a few of them, and each one follows a rule simple enough to fit in a small table. These lessons take you from your first gate to circuits that add numbers, remember and count, one small step at a time.
Every lesson explains one idea and ends with a challenge that you solve in GateLab, a free logic circuit simulator that runs in your browser. Your circuit is checked automatically, and you earn up to three stars for using few parts. Nothing to install, no account needed.
Start with the first challenge It shows you how to draw a wire. It takes one minute.
1. The basic gates
What each gate does, with its symbol and truth table.
- Logic gatesA logic gate is a tiny circuit that takes one or more inputs, each 0 or 1, and gives an output that is also 0 or 1.
- ANDThe AND gate gives 1 only when all of its inputs are 1.
- ORThe OR gate gives 1 when at least one of its inputs is 1.
- NOTThe NOT gate, also called an inverter, has one input and gives the opposite value: 0 becomes 1 and 1 becomes 0.
- NANDThe NAND gate is an AND gate followed by a NOT: “not and”.
- NORThe NOR gate is an OR gate followed by a NOT: “not or”.
- XORThe XOR gate (exclusive OR) gives 1 when its two inputs are different, and 0 when they are the same.
- XNORThe XNOR gate is an XOR followed by a NOT.
2. Everything from NAND
One kind of gate is enough to build all the others.
- NOT from NANDY must be the opposite of A, using only NAND gates.
- AND from NANDY = A AND B, using only NAND gates.
- OR from NANDY = A OR B, using only NAND gates.
- XOR from NANDY is 1 when A and B differ. Only NAND gates.
3. Adding numbers
From adding two bits to adding whole numbers.
- Half adderAdd two bits: S is the sum bit, C the carry.
- Full adderAdd three bits (A + B + Cin): S is the sum bit, Cout the carry.
- 4-bit adderAdd two 4-bit numbers: S is the 4-bit sum, Cout the carry out.
4. Choosing and comparing
Circuits that pick a signal, select an output or compare numbers.
- MultiplexerY shows A when Sel is 0, and B when Sel is 1.
- 2-to-4 decoderExactly one output is 1: the one numbered S1 S0 in binary.
- Equality comparatorEQ is 1 when the 2-bit numbers A1 A0 and B1 B0 are equal.
5. Memory and time
Circuits that remember, and circuits that count clock pulses.
- SR latchS = 1 sets Q to 1, R = 1 resets it to 0. With both at 0, Q must remember.
- D flip-flopQ takes the value of D only at the moment CLK goes from 0 to 1, and holds it otherwise.
- 2-bit counterEach time CLK goes from 0 to 1, Q1 Q0 counts up: 0, 1, 2, 3, then back to 0.
How the lessons work
Read the lesson, look at the truth table and try the inputs on the page. Then press Try the challenge: GateLab opens with the inputs and outputs already placed, and you add the gates and wires in between. Press Check to see whether your circuit is right. If you get stuck, every challenge has hints, and each lesson has a solution you can open.
Start with the very first challenge, which shows you how to draw a wire: First steps.
Questions
What is the best way to learn logic gates?
Learn the rule of each gate with its truth table, then build circuits with them yourself. Building something, even something small, makes the rules stick much better than reading alone. That is why every lesson here ends with a challenge.
Do I need to know electronics?
No. Logic gates work with only two values, 0 and 1, and you can learn them like a puzzle. Electronics explains how gates are made from transistors, but you don’t need it to design circuits.
Is it free?
Yes. The lessons and the simulator are free and work in any modern browser, at home or at school.