Boolean Logic — The Language of Computers
PlayHow AND, OR, and NOT gates make every decision a computer ever makes
This concept builds on Binary Numbers — How Computers Count. Consider exploring it first for the best experience.
True or False
A boolean value is either TRUE (1) or FALSE (0). Every decision a computer makes comes down to this one bit.
AND gate
AND outputs 1 only when BOTH inputs are 1. In a circuit: current flows only if switch A AND switch B are both closed.
OR gate
OR outputs 1 when AT LEAST ONE input is 1. Current flows if switch A OR switch B (or both) are closed.
NOT gate
NOT flips the bit. NOT(1) = 0, NOT(0) = 1. This is an inverter — true becomes false, false becomes true.
Combining gates
Any logic can be built from these three gates. NAND (NOT AND) and NOR (NOT OR) alone can build anything. Modern CPUs contain billions of gates.
What-if: swap the 4th gate
Use the gate selector to swap the fourth row between XOR, NAND, NOR, and XNOR. Keep your A/B inputs fixed and watch the live truth table update as you switch — a great way to see exactly where each gate agrees or disagrees with AND/OR/NOT.
What-if: prove NAND is universal
Check "Rebuild AND/OR/NOT using only NAND gates" to replace the AND, OR, and NOT gate symbols with the actual chain of NAND gates that reproduces them: NOT(A) = NAND(A, A); AND(A, B) = NAND(NAND(A, B), NAND(A, B)); OR(A, B) = NAND(NAND(A, A), NAND(B, B)). Toggle your inputs and watch every intermediate NAND output update live — the final box still matches the direct gate, proving NAND alone is enough to build any circuit.
Challenge: name the mystery gate
Check "Challenge: Identify the mystery gate" and the fourth row hides its name behind a "?". It is one of AND, OR, XOR, NAND, NOR or XNOR. Click its A and B boxes to test input pairs — each tested row fills in the truth table and narrows "Gates that still fit". Name it with a gate button; a wrong guess shows a tested row that rules your guess out. Three tests are always enough, and two never are: two tests give only four possible answers for six gates.
How It Works — Step by Step
-
1
True or False
A boolean value is either TRUE (1) or FALSE (0). Every decision a computer makes comes down to this one bit.
-
2
AND gate
AND outputs 1 only when BOTH inputs are 1. In a circuit: current flows only if switch A AND switch B are both closed.
-
3
OR gate
OR outputs 1 when AT LEAST ONE input is 1. Current flows if switch A OR switch B (or both) are closed.
-
4
NOT gate
NOT flips the bit. NOT(1) = 0, NOT(0) = 1. This is an inverter — true becomes false, false becomes true.
-
5
Combining gates
Any logic can be built from these three gates. NAND (NOT AND) and NOR (NOT OR) alone can build anything. Modern CPUs contain billions of gates.
-
6
What-if: swap the 4th gate
Use the gate selector to swap the fourth row between XOR, NAND, NOR, and XNOR. Keep your A/B inputs fixed and watch the live truth table update as you switch — a great way to see exactly where each gate agrees or disagrees with AND/OR/NOT.
-
7
What-if: prove NAND is universal
Check "Rebuild AND/OR/NOT using only NAND gates" to replace the AND, OR, and NOT gate symbols with the actual chain of NAND gates that reproduces them: NOT(A) = NAND(A, A); AND(A, B) = NAND(NAND(A, B), NAND(A, B)); OR(A, B) = NAND(NAND(A, A), NAND(B, B)). Toggle your inputs and watch every intermediate NAND output update live — the final box still matches the direct gate, proving NAND alone is enough to build any circuit.
-
8
Challenge: name the mystery gate
Check "Challenge: Identify the mystery gate" and the fourth row hides its name behind a "?". It is one of AND, OR, XOR, NAND, NOR or XNOR. Click its A and B boxes to test input pairs — each tested row fills in the truth table and narrows "Gates that still fit". Name it with a gate button; a wrong guess shows a tested row that rules your guess out. Three tests are always enough, and two never are: two tests give only four possible answers for six gates.
Key Takeaways
Three fundamental operations
AND, OR, NOT are the building blocks of all digital logic. Every chip, every CPU, every decision is built from these.
Truth tables
A truth table lists all input combinations and the output for each. AND has 4 rows (2 inputs × 2 states), OR has 4 rows, NOT has 2.
NAND is universal
Any logic gate can be built from NAND alone. Real chips use NAND because it's physically efficient to manufacture. Toggle "Rebuild using only NAND gates" above to see the actual NAND chains behind AND, OR, and NOT.
A gate is its truth table
Two gates that give the same output for every input pair are the same gate. That is why testing rows in the mystery-gate challenge pins the hidden gate down — and why three well-chosen tests always tell six two-input gates apart.
Connects to binary
Boolean logic operates on individual bits — the 0s and 1s of binary. Add enough logic gates and you get arithmetic, memory, and computation.
Connected Concepts
Binary
Boolean logic operates on 0s and 1s.
Sorting
Every comparison in a sorting algorithm is a boolean decision.
Transistors
Wire a handful of transistors together and their on/off states physically become these AND, OR, and NOT gates.
Set Theory
AND, OR and NOT are intersection, union and complement in disguise: an element is in A ∩ B exactly when "in A" AND "in B" are both true.
Updated
- — New mystery-gate challenge: test input pairs and name the hidden gate. New step, two quiz questions, Set Theory link.