Boolean Logic — The Language of Computers

Play

How AND, OR, and NOT gates make every decision a computer ever makes

Computer Science Foundations beginner 5 min

This concept builds on Binary Numbers — How Computers Count. Consider exploring it first for the best experience.

Step 1 of 8

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.

Play Gate Works A game about Boolean Logic — The Language of Computers

How It Works — Step by Step

Step 1 of 8
  1. 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. 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. 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. 4

    NOT gate

    NOT flips the bit. NOT(1) = 0, NOT(0) = 1. This is an inverter — true becomes false, false becomes true.

  5. 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. 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. 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. 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.

Added
Updated
  • — New mystery-gate challenge: test input pairs and name the hidden gate. New step, two quiz questions, Set Theory link.