Electronics School · Stage 4: Explore Digital Electronics · Lesson 20

Logic Gates

The tiny decision-makers that every computer is built from.

The question

How does a car know to beep only when the key is in AND the door is open?

What you’ll discover: what logic gates are, how to read a truth table, and how gates combine to make decisions.

In simple terms

BeginnerYes-or-no decisions

A logic gate is a tiny circuit that looks at one or more inputs, each 0 or 1, and produces an output of 0 or 1 according to a simple rule:

  • AND: output is 1 only if A and B are both 1. (The key is in AND the door is open: beep.)
  • OR: output is 1 if A or B (or both) is 1. (Either door open: turn on the dome light.)
  • NOT: one input, and the output is the opposite. (Bright, 1, in: night light off, 0, out. Dark, 0, in: night light on, 1, out.)

A truth table lists every possible input combination and the output for each.

Try it: logic gate lab

Choose a gate, then switch inputs A and B on and off.

Go deeper

IntermediateMore gates, and gates from transistors

Three more gates come up often: NAND (NOT AND: 0 only when both inputs are 1), NOR (NOT OR: 1 only when both inputs are 0) and XOR (exclusive OR: 1 when the inputs are different).

Gates are built from transistors. You’ve already seen the idea: in the Touch Switch and Night Light, a transistor turns an output on or off depending on its input. Two transistor switches in series make an AND; two in parallel make an OR.

You can try gates for real with chips from the common 74HC family, such as the 74HC08 (four AND gates in one chip), powered by a 3 × AA (4.5 V) battery pack. 74HC chips are rated for 2 to 6 V, so never use a 9 V battery. Connect any unused inputs to + or −, because a floating input can make the chip behave unpredictably.

AdvancedUniversal gates and adding numbers

NAND is called a universal gate: any logic circuit at all can be built from NAND gates alone (NOR is universal too). For example, a NOT is a NAND with both inputs joined.

An XOR and an AND together make a half adder, which adds two bits: XOR gives the sum bit and AND gives the carry. Chain adders together and you can add numbers of any size. That’s the beginning of how a computer’s processor does arithmetic.

Quick check

What does an AND gate output when A is 1 and B is 0?

0. AND needs both inputs to be 1.

Which gate outputs 1 only when its inputs are different?

XOR (exclusive OR).

Why is NAND called a universal gate?

Any logic circuit can be built from NAND gates alone.

Words to know

Logic gate
A circuit that makes a yes/no decision from its inputs.
Truth table
A table of every input combination and its output.
XOR
Exclusive OR: 1 when the inputs differ.
Half adder
A circuit that adds two bits, using XOR and AND.

Electronics School is part of the Discovery Zone. Every activity here runs on small batteries or a USB cable: never wall outlets. The one plug-in tool is the optional soldering iron, set up by an adult.

Was this page helpful?
Get all four of our sites in one free email every Friday: Prairie Signals
⇧Top
Hello! “Isn't it strange that each new generation has to learn the stove is hot?”