← SciSim / Computer Science

Logic Gates Simulator

Grades 6–8 first · high school depth in “Go deeper” · computer science
Flip the switches. The picture, the circuit and the truth table always agree.

What is a logic gate?

A logic gate is a tiny electronic circuit that turns one or more inputs into a single output, each either 1 (on) or 0 (off). There are 7 basic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR. A truth table lists the output for every input, and gates combined in circuits make every computer chip work.

In this lab you can

Steps in this lab: 1 Meet the gates · 2 Combine · 3 Build · 4 Challenges

The 7 logic gates AND, OR, NOT, NAND, NOR, XOR and XNOR with their symbols and truth tables
The 7 logic gates: symbols and truth tables. A yellow cell is an output of 1 (ON).

What is a logic gate?

A logic gate is a small circuit that follows one fixed rule to turn its inputs into an output. Every input and output is either 1 (on, high voltage) or 0 (off, low voltage), so a gate works with yes-or-no answers.

Real gates are built from transistors, tiny switches on a chip. (source: Dive into Systems, 5.3 Logic Gates) A modern chip holds billions of them: Apple’s M3 chip has 25 billion transistors. (source: Apple Newsroom, 30 Oct 2023)

You already know the idea from daily life. A microwave runs only when the door is closed and Start is pressed; that rule is an AND gate. In the lab you can tap the door and the button and watch the same rule in a circuit and a truth table.

What is an AND gate?

An AND gate gives an output of 1 only when all of its inputs are 1.

AND gate truth table
ABOutput
000 OFF
010 OFF
100 OFF
111 ON

Rule: Lamp = A AND B

Real life: A microwave runs only when the door is closed AND Start is pressed. If either one is missing, it stays off.

With two inputs there are 4 possible rows, and only 1 of them (1 and 1) turns the output on. AND gates can also have three or more inputs. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the AND gate in the lab →

What is an OR gate?

An OR gate gives an output of 1 when at least one of its inputs is 1.

OR gate truth table
ABOutput
000 OFF
011 ON
101 ON
111 ON

Rule: Lamp = A OR B

Real life: A doorbell rings when the front button OR the back button is pressed. Pressing both still rings it.

OR is on in 3 of the 4 rows; it is off only when every input is 0. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the OR gate in the lab →

What is a NOT gate?

A NOT gate (also called an inverter) has one input and gives the opposite value: 1 becomes 0 and 0 becomes 1.

NOT gate truth table
AOutput
01 ON
10 OFF

Rule: Lamp = NOT A

Real life: A night light glows when the room light is NOT on.

A one-input gate has only 2 rows in its truth table. The small circle on its symbol means “flip it”. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the NOT gate in the lab →

What is a NAND gate?

A NAND gate (NOT AND) gives an output of 0 only when all of its inputs are 1; in every other case it gives 1.

NAND gate truth table
ABOutput
001 ON
011 ON
101 ON
110 OFF

Rule: Lamp = NOT (A AND B)

Real life: A school bus warning light stays on unless the front door and the back door are both closed.

Its truth table is the exact opposite of AND: 3 of the 4 rows are ON. NAND is one of the two universal gates. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the NAND gate in the lab →

What is a NOR gate?

A NOR gate (NOT OR) gives an output of 1 only when all of its inputs are 0.

NOR gate truth table
ABOutput
001 ON
010 OFF
100 OFF
110 OFF

Rule: Lamp = NOT (A OR B)

Real life: An air conditioner runs only when neither the window NOR the door is open.

NOR is ON in just 1 of the 4 rows (0 and 0). Like NAND, it is a universal gate, and it can have more than two inputs. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the NOR gate in the lab →

What is an XOR gate?

An XOR gate (exclusive OR) gives an output of 1 when its two inputs are different, and 0 when they are the same.

XOR gate truth table
ABOutput
000 OFF
011 ON
101 ON
110 OFF

Rule: Lamp = A XOR B

Real life: A stair light with a switch at the bottom and one at the top: it is on when exactly one switch is up. Flip either switch and the light changes.

XOR is ON in 2 of the 4 rows: 0 and 1, or 1 and 0. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the XOR gate in the lab →

What is an XNOR gate?

An XNOR gate (exclusive NOR) gives an output of 1 when its two inputs are the same, and 0 when they are different.

XNOR gate truth table
ABOutput
001 ON
010 OFF
100 OFF
111 ON

Rule: Lamp = NOT (A XOR B)

Real life: A match light turns on when two players pick the same shape.

XNOR is the opposite of XOR: it is ON for 0 and 0, and for 1 and 1. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))

Try the XNOR gate in the lab →

What is a truth table?

A truth table is a chart that lists every possible set of inputs and the output a gate or circuit gives for each one.

Each new input doubles the rows. A two-input gate has 4 rows (00, 01, 10, 11) and a three-input gate has 8 rows. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt)) In the lab, tap any row of the table to set the switches to that row.

The rows always go in counting order, like binary numbers: 00, 01, 10, 11. That way you never miss a case. To see how binary counting works, try the Binary Numbers Lab; to turn words into 0s and 1s, try the Binary Translator.

Which logic gate does what? (all 7 compared)

GateSymbolRuleOutput is 1 when…Real-life example
ANDA AND Ball inputs are 1microwave
ORA OR Bat least one input is 1doorbell
NOTNOT Athe input is 0night light
NANDNOT (A AND B)not all inputs are 1bus warning light
NORNOT (A OR B)all inputs are 0air conditioner
XORA XOR Bthe inputs are differentstair light
XNORNOT (A XOR B)the inputs are the samematch light

A small circle on a symbol always means NOT. That is why NAND, NOR and XNOR look like AND, OR and XOR with a circle at the output. In the lab, tap that circle to switch between the pairs.

How do logic gates work?

A logic gate works like a group of switches that decide whether current reaches the output. Two switches in a row (series) make AND: the lamp lights only if both are closed. Two switches side by side (parallel) make OR: either one lights it. You can try both kinds of wiring in the series and parallel circuits lab.

Inside a chip, the switches are transistors, so a gate needs no moving parts. (source: Dive into Systems, 5.3 Logic Gates) The math behind it is Boolean algebra, which works with just two symbols, 1 and 0. Claude Shannon showed in his MIT master’s thesis that this algebra can describe switching circuits; it became the base of digital circuit design. (source: MIT News, 2001)

How do you combine logic gates? (worked example: a home alarm)

You combine logic gates by wiring the output of one gate into an input of the next, so the circuit follows a longer rule.

A home alarm should sound when it is armed (A) AND the door (B) OR the window (C) is open. That rule needs two gates: Alarm = A AND (B OR C). Work it out one gate at a time:

  1. Find the middle wire first: B OR C is 1 if the door or the window is open.
  2. Then the AND gate: the alarm is 1 only if A is 1 and the middle wire is 1.
  3. Three inputs give 8 rows, so check all 8. (source: Lessons In Electric Circuits, Vol. IV, ch. 3 (Kuphaldt))
Home alarm truth table: Alarm = A AND (B OR C)
A armedB door openC window openB OR CAlarm
00000 OFF
00110 OFF
01010 OFF
01110 OFF
10000 OFF
10111 ON
11011 ON
11111 ON

Result: the alarm sounds in 3 of the 8 rows, all of them with A = 1. Disarmed (A = 0), it stays quiet whatever the door does. Open the home alarm in the lab → The same step also shows XOR built from AND, OR and NOT, and two gates that add 1 + 1 = 10 in binary.

How can you build your own logic circuit?

A logic circuit is a set of gates wired so that switches go in on the left and lamps come out on the right.

In the Build step you get 2 or 3 switches, up to 6 gates in 3 columns and 1 or 2 lamps. Tap a gate, tap a free place, then tap an output dot and an input dot to draw a wire. Wires always run left to right, so a loop cannot form. An input with no wire shows “not connected”, never a silent 0. The truth table of your circuit fills in as you wire, and you can save a finished circuit as a block.

Start building in the lab →

What are the universal gates?

The universal gates are NAND and NOR: with enough of either one alone, you can build every other gate.

“NAND and NOR gates possess a special property: they are universal.”

With NAND gates only, NOT takes 1 gate (feed the same input into both inputs), AND takes 2, OR takes 3 and XOR takes 4. A NAND gate by itself is enough to make any logic circuit. (source: Dive into Systems, 5.3 Logic Gates)

Try the NAND-only challenge →

How can you test what you know about logic gates?

A logic-gate challenge asks you to work backward from a truth table to the gates that make it.

Every answer is checked against the full truth table, so any correct circuit counts. Your done marks stay on this device. Open the challenges →

Go deeper (high school): notation, De Morgan’s laws, box symbols

How are logic gates written in Boolean algebra?

AND is written as a dot or no sign: A·B or AB. OR is a plus: A + B. NOT is a bar over the letter (A̅) or a prime: A′. XOR is A ⊕ B. So the home alarm is A·(B + C).

What are De Morgan’s laws?

De Morgan’s laws say that NOT (A AND B) = (NOT A) OR (NOT B) and NOT (A OR B) = (NOT A) AND (NOT B). So a NAND gate gives the same table as an OR gate with a NOT on each input. Check it in the lab: build NOT A, NOT B and OR them, then compare with the NAND table.

De Morgan check: NOT (A AND B) = (NOT A) OR (NOT B)
ABNOT (A AND B)(NOT A) OR (NOT B)
0011
0111
1011
1100

Why are NAND and NOR universal?

AND, OR and NOT together can build any circuit. (source: Dive into Systems, 5.3 Logic Gates) NAND can make NOT (tie both inputs together), AND (NAND then NOT) and OR (NOT each input, then NAND). Since it makes all three, it makes everything. NOR works the same way with the roles of AND and OR swapped.

What do XOR gates with 3 inputs do?

An XOR with more than two inputs gives 1 when an odd number of inputs are 1. This “parity” rule is used to spot errors in stored data.

What are the box-shaped gate symbols?

Besides the curved shapes used here, a second standard draws every gate as a rectangle with a sign inside: & for AND, ≥1 for OR, =1 for XOR and 1 for a NOT (buffer box with a circle). Both mean the same thing.

Quantum computers use a very different kind of gate that works on qubits; see the Bloch sphere and qubits lab.

❓ FAQ

There are 7 basic logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR. NOT has one input; the other six usually have two inputs, and AND, OR, NAND and NOR are also made with three or more inputs (XOR and XNOR can be too).

Key takeaway: Seven basic gates.

Yes. AND, OR, NAND and NOR gates can have three or more inputs. A three-input AND gives 1 only when all three inputs are 1, and its truth table has 8 rows instead of 4.

Key takeaway: Yes: 3 inputs means 8 rows.

Because you can build every other gate from NAND gates alone, or from NOR gates alone. For example, NOT takes 1 NAND gate, AND takes 2 and OR takes 3.

Key takeaway: NAND alone (or NOR alone) can make any gate.

OR gives 1 when at least one input is 1, including when both are 1. XOR gives 1 only when exactly one input is 1, so for 1 and 1 OR gives 1 but XOR gives 0.

Key takeaway: They differ only in the 1 and 1 row.

Logic gates make every digital device work: phones, computers, game consoles, traffic lights and microwaves. A processor chip uses billions of transistors wired as gates to add numbers, compare them and store data.

Key takeaway: Every digital device is built from gates.

Teacher notes

Level: grades 6–8 first (Steps 1–2), grades 9–12 for Build, Challenges and “Go deeper”. Time: one 45-minute lesson, or two with the challenges.

  1. Hook (5 min): project the microwave (full screen). Ask: “What has to be true for it to run?” Flip the door and Start. Then tap the little circle on the output and ask why every row of the table flipped.
  2. Meet the gates (15 min): turn on Guess first. For each gate, students call ON or OFF before you reveal the lamp; the lab counts right answers.
  3. Combine (10 min): home alarm. Students fill in the 8-row table on the worksheet (For teachers → Print worksheet makes it from the board, with the answer key on page 2).
  4. Exit task (10 min): the mystery gate challenge, or “Give this to the class” to share a challenge by link or QR code.

Common mix-ups: OR is not “one or the other but not both” (that is XOR); the small circle means NOT; a wire that is not connected is unknown, not 0; rows of a truth table go in binary counting order.

Standards: in the CSTA K–12 Computer Science Standards (2017), the one standard that names logic is 3B-CS-02 (grades 11–12): “Illustrate ways computing systems implement logic, input, and output through hardware components.” (source: CSTA K–12 Computer Science Standards, revised 2017) For grades 6–8 the lab is enrichment that builds toward it.

Sources

Next lab: chain these gates into a 4-bit calculator in the Full Adder Simulator. Related labs: series and parallel circuits, qubits and the Bloch sphere, binary numbers, the binary translator and binary search.