Skip to content
digiwleea
The theory Tools Open the lab →

Logic gates: how they work, with symbols and truth tables

Every computer, all of it, is built from a handful of tiny rules called logic gates. Each takes a bit or two and outputs one bit. Meet them here, and click their inputs.

Toggle the A and B inputs and watch the output lamp and truth table. Press Next gate to meet the next one.

What just happened

A logic gate is a tiny decision-maker. Its inputs are bits, either 0 (off, low voltage) or 1 (on, high voltage), and it outputs a single bit by a fixed rule you can read straight off its truth table. AND means "both", OR means "either", NOT flips, and XOR means "different". That is genuinely all a gate does, and it never changes its mind: the same inputs always give the same output.

The magic is in combining them. Wire an XOR and an AND together and you get a half adder that adds two bits. Cross-couple two NOR gates and you get a circuit that remembers a bit. Stack millions of gates and you get a CPU. And because NAND is universal (every other gate can be built from it), a chip can be etched from a single gate type. Gates themselves are built from transistors, tiny voltage-controlled switches. That is the whole ladder: switches to gates to arithmetic to a computer. Build any of it yourself in the lab.

Each gate has its own page with its symbol, truth table and a live gate to click: the AND gate, OR gate, NOT gate, NAND gate, NOR gate, XOR gate and XNOR gate, or see all seven logic gate symbols and truth tables on one page.

Test yourself with the logic gates practice quiz: gate outputs, truth tables and small circuits, with the reason for every answer.

All seven logic gates at a glance

GateSymbolExpressionOutput is 1 whenY for AB = 00, 01, 10, 11Common ICCMOS transistors
NOT (inverter)Triangle with a bubbleY = A'A is 01, 0 (for A = 0, 1)74042
ANDD shapeY = A · Bboth inputs are 10 0 0 174086
ORCurved shieldY = A + Bat least one input is 10 1 1 174326
NANDAND with a bubbleY = (A · B)'not both inputs are 11 1 1 074004
NOROR with a bubbleY = (A + B)'both inputs are 01 0 0 074024
XOROR with an extra curveY = A ⊕ Bthe inputs differ0 1 1 0748612
XNORXOR with a bubbleY = (A ⊕ B)'the inputs are equal1 0 0 174LS26612

Each IC holds several gates: four 2-input gates in the 7400, 7402, 7408, 7432 and 7486, six inverters in the 7404, and four open-collector XNOR gates in the 74LS266. Transistor counts are for standard static CMOS; AND and OR are a NAND or NOR plus an inverter.

Universal gates: NAND and NOR

NAND and NOR are called universal gates because each one alone can build NOT, AND and OR, and therefore any logic circuit. Tie a NAND's inputs together and it is a NOT; follow a NAND with a NOT and it is an AND; invert both inputs of a NAND and it is an OR. See it working in the live gates built from NAND and gates built from NOR, then bigger circuits from NAND alone: XOR from four NANDs, a half adder and a multiplexer.

Exam-style questions, with answers

1. What is the output of a 3-input NAND gate for inputs 1, 1, 0?

1. A NAND outputs 0 only when every input is 1; here one input is 0.

2. For A = 1 and B = 0, give the output of all seven gates.

NOT A = 0, AND = 0, OR = 1, NAND = 1, NOR = 0, XOR = 1, XNOR = 0.

3. Which single gate is an AND gate followed by a NOT gate?

NAND: Y = (A · B)'. Likewise an OR followed by a NOT is a NOR.

4. What is the minimum number of 2-input NAND gates needed to make an XOR gate?

Four. NAND(A, B) is shared: Y = NAND(NAND(A, N), NAND(B, N)) with N = NAND(A, B). Try the live circuit.

5. Which gate can be used as a controlled inverter, and how?

XOR: A XOR 0 = A and A XOR 1 = NOT A, so one input decides whether the other passes through unchanged or inverted.

More practice: the logic gates quiz checks your answers and explains each one.

Common questions

How do logic gates work?

Each gate takes one or two input bits (0 or 1) and outputs one bit by a fixed rule: AND = both, OR = either, NOT = flip, XOR = differ. Gates are built from transistors, and combining them builds every circuit in a computer.

What are the basic logic gates?

NOT, AND, and OR are the core, plus XOR (differ) and the inverted forms NAND and NOR. NAND and NOR are each universal: every other gate can be built from just that one type.

What is a logic gate in simple terms?

A tiny decision-maker: feed it input bits (0 = off, 1 = on) and it outputs a single 0 or 1 by a simple rule. An AND gate outputs 1 only if all inputs are 1. Stack enough of these and you get a computer.

Why is NAND called universal?

Because every other gate can be built from NAND gates alone: a NOT is a NAND with tied inputs, AND is NAND then NOT, and so on. So a chip can be made from a single gate type, one reason NAND is everywhere in real hardware.

What are logic gates used for?

Everything digital: adders and multipliers, decision logic, and, with feedback, memory. Millions to billions of gates make a CPU. Every program becomes patterns of gates switching.

Build your own gates from transistors in the lab →

Embed this interactive

Free to embed in your course page, blog, or notes: just keep the credit link under the widget. Paste this where you want it:

<iframe src="https://digiwleea.wleeaf.dev/embed/tool/?w=gates" width="100%" height="500" style="border:0;border-radius:12px;max-width:600px" title="How logic gates work" loading="lazy"></iframe>