Logic Gates Explained: AND, OR, NOT, NAND, NOR, XOR (Truth Tables)
The 7 basic logic gates — AND, OR, NOT, NAND, NOR, XOR, XNOR — with truth tables, everyday examples and a free logic gate simulator.
ON THIS PAGE
Every phone, laptop and game console is built from billions of tiny decisions. Each decision is made by a logic gate: a little circuit that looks at one or two ON/OFF inputs and decides if its output is ON or OFF. Learn seven gates and you know the alphabet of every computer.
Free logic gate simulator
Flip the two switches and watch each gate decide whether the lamp lights. The highlighted row of the truth table is your switches right now.
⚡ LOADING THE CALCULATOR…
Free, no sign-up. Prefer a bigger screen? Open the Logic gates calculator in the Lab →
ON and OFF: 1 and 0
In digital electronics, a wire is either HIGH (1) — near the supply voltage, like 5 V or 3.3 V — or LOW (0), near 0 V. A truth table lists the output for every possible combination of inputs. With two inputs there are only four rows: 00, 01, 10, 11.
The 7 basic logic gates
AND gate
Output is 1 only when both inputs are 1. Everyday example: a machine that starts only when both safety buttons are pressed.
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR gate
Output is 1 when A or B (or both) is 1. Example: a car's interior light turns on if any door is open.
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NOT gate (inverter)
One input, and the output is the opposite. 1 → 0, 0 → 1. Example: a night light — not daylight → lamp on.
NAND gate
AND, then NOT. Output is 0 only when both inputs are 1. NAND is a universal gate: you can build every other gate (and a whole computer) from NAND gates alone. Flash memory is even named after it (NAND flash).
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOR gate
OR, then NOT. Output is 1 only when both inputs are 0. Also universal.
XOR gate (exclusive OR)
Output is 1 when the inputs are different. Example: a staircase light with a switch at the top and the bottom — flipping either switch changes the light.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XNOR gate
XOR flipped: output is 1 when the inputs are the same. It is an "equality checker".
All gates in one table
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
How gates are made
Inside a chip, each gate is a few transistors used as switches. A CMOS NAND gate uses just four. Put billions together and you get adders, memory and a whole processor. You can also buy gates as small chips: the 74HC08 (four AND gates), 74HC00 (four NAND), 74HC86 (four XOR).
Gates in code
You use logic gates every time you write an if:
if (buttonA && buttonB) { } // AND
if (doorOpen || keyIn) { } // OR
if (!isDay) { } // NOT
x = a ^ b; // XOR on bits
A half adder: gates that do maths
Add two bits with just two gates: XOR gives the sum bit and AND gives the carry. 1 + 1 → XOR = 0, AND = 1 → binary 10 = 2. Chain these and a computer can add any numbers — see binary and hex.
Frequently asked questions
What are the basic logic gates?
AND, OR and NOT are the three basic gates. NAND, NOR, XOR and XNOR are built from them, giving seven common gates.
What is the difference between OR and XOR?
OR is 1 when at least one input is 1 (including both). XOR is 1 only when exactly one input is 1 — when the inputs are different.
Why is NAND called a universal gate?
Because any other gate — and therefore any digital circuit — can be built using only NAND gates.
What is a truth table?
A table listing the output of a logic circuit for every possible combination of inputs.





