Lesson 7 of 7 · about 12 min
Logic gates
A logic gate is a tiny circuit that looks at on/off inputs and produces an on/off output by a simple rule (AND, OR, NOT). Every computer is built from billions of them.
🧭 What you need first: Counting with switches
A hallway light with two switches, one at each end: flip either one and the light changes. A car that only starts if the key is turned and the brake is pressed. A doorbell that rings if the front button or the back button is pressed.
These are all little decision rules about on/off things. Logic gates are tiny electronic circuits that make exactly these decisions. Each one takes one or two bits in and gives one bit out.
Here’s the mind-blowing part: there’s no magic component inside a computer that “does math” or “thinks.” It’s billions of these simple yes/no gates, wired together cleverly.
Another way: two keys for a safe
Bank vaults often need two people to turn their keys at the same time. That’s AND: both must be “on.” A house with two doors is OR: either key gets you in.
Another way: a light switch on a timer
NOT is the “opposite day” rule: the porch light turns ON when it’s NOT bright outside. One input, flipped.
Try every gate
Pick a gate, flip the inputs, and watch the output bulb and the truth table. Try all the combinations for each gate.
AND: On only if BOTH inputs are on.
| A | B | out |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The real words
- A logic gate computes one output bit from its input bits.
- A truth table lists every input combination. With 2 inputs there are 4 rows (2²). Remember the doubling rule from lesson 1!
| A | B | A AND B | A OR B | A XOR B | NOT A |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
- Boolean algebra is the math of 0/1 values, written with AND (·), OR (+) and NOT (¬ or a bar). It lets engineers simplify circuits on paper.
- Gates are built from transistors, which are switches controlled by electricity instead of fingers. A NAND gate needs about 4.
- NAND is universal: you can build NOT, AND, OR, XOR, and so every circuit in a computer, out of NAND gates alone. (NOT A = A NAND A.) Building a computer from NAND upward is a classic project you’ll do in F14.
- You’ll meet these same operations in programming: Python’s
and,or,not(F02).
Read the circuit
A security alarm should sound when the system is armed AND (a door OR a window opens). The system is armed, the door is closed, the window is open. Does it sound?
Build NOT from NAND
A NAND gate outputs 0 only when both inputs are 1. If you connect the SAME signal A to both inputs, what does it compute?
How many rows does a truth table for a 3-input gate need?
Got it?
Finish the lesson to color it in on your map and collect its concept cards.
Did this lesson click?