What is a logic gate?
A logic gate is a small digital circuit that takes one or more inputs, each high (1) or low (0), and produces a single output that is also 1 or 0. Which output appears depends only on the combination of inputs and on the type of gate. Most gates have two inputs and one output; the NOT gate is the exception, with one input and one output.
Gates are the decision-makers inside smartphones, computers, calculators and digital watches. Millions of them, joined together, process the binary data that these devices store.
The five gates in this chapter
In the equations below, A and B are the inputs and X is the output.
- AND gate: . The output is 1 only if A and B are both 1. Symbol: a shape with a flat back and a rounded, D-shaped front.
- OR gate: . The output is 0 only if A and B are both 0; any 1 at the input gives 1. Symbol: a curved back and a pointed front, like a shield.
- NOT gate (inverter): . One input, and the output is always the opposite. Symbol: a triangle with a small circle (bubble) at its tip.
- NAND gate (NOT AND): . An AND gate followed by a NOT gate. The output is 0 only when both inputs are 1. Symbol: the AND shape with a bubble on the output.
- NOR gate (NOT OR): . An OR gate followed by a NOT gate. The output is 1 only when both inputs are 0. Symbol: the OR shape with a bubble on the output.
The bubble always means "invert here". The bar drawn over an expression means NOT of everything under it.
All the truth tables together
| A | B | AND | OR | NAND | NOR |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
For the NOT gate: input 0 gives output 1, and input 1 gives output 0.
Notice that the NAND column is the AND column with every value flipped, and the NOR column is the OR column flipped. That is a quick way to check a table in an exam.
Worked example 1: reading a gate
A NAND gate has A = 1 and B = 0. What is its output?
First find AND: . Then invert it: NOT 0 = 1. A NAND output is 0 only for the single row where both inputs are 1.
Worked example 2: a NOR gate followed by a NOT gate
Show that a NOR gate whose output feeds a NOT gate behaves as an OR gate.
| A | B | NOR output | after NOT |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 |
The final column matches OR exactly. Inverting twice cancels out, leaving the OR that was inside the NOR.
Worked example 3: two NOT gates into a NOR gate
Each input passes through its own NOT gate before reaching a NOR gate. Show the result is AND.
- A = 0, B = 0: the NOR gate receives 1 and 1, so it gives 0.
- A = 0, B = 1: it receives 1 and 0, so it gives 0.
- A = 1, B = 0: it receives 0 and 1, so it gives 0.
- A = 1, B = 1: it receives 0 and 0, the only case where NOR gives 1.
The output is 1 only when both A and B are 1, which is AND. Going beyond the book: a NOR gate with its two inputs joined together works as a NOT gate, so NOR gates alone can be combined to make every other gate.
Uses of logic gates (section 19.5): a burglar alarm
A single NAND gate can run a simple burglar alarm.
- Input B comes from an LDR connected to the positive side of the supply (beyond the book: a fixed resistor from B to the negative side completes a potential divider). While light shines on the LDR its resistance is low, so B is high (1). If an intruder blocks the light, the LDR's resistance rises and B falls low (0).
- Input A comes from a hidden push switch, arranged so that A is normally high (1) and goes low (0) when someone steps on it.
- The output drives the alarm.
| Situation | A | B | NAND output | Alarm |
|---|---|---|---|---|
| All quiet | 1 | 1 | 0 | silent |
| Light beam blocked | 1 | 0 | 1 | sounds |
| Mat switch pressed | 0 | 1 | 1 | sounds |
| Both | 0 | 0 | 1 | sounds |
Because a NAND gate stays at 0 only while every input is 1, any single disturbance sets off the alarm.
Uses of logic gates: a fire alarm
A fire alarm should react to smoke or heat. A smoke sensor feeds input A and a heat sensor feeds input B of an OR gate. If either sensor (or both) gives a 1, the output becomes 1 and can switch on a siren and start a sprinkler or extinguisher. Simple alarms can also be made from parts such as thermistors, timer chips and operational amplifiers, but an OR gate captures the logic: smoke OR heat means fire.
Logic gates in the simulation
The circuit builder has no gate chips, but switch circuits and an LDR show the same behaviour.
- From Starting circuits, choose Empty. Place two Switch parts in series with a Lamp, select each in turn and tick or untick Switch closed: the lamp follows the AND column.
- Rebuild with the switches on separate branches: the lamp now follows the OR column.
- Load LDR divider. Select the fixed Resistor and move the Light level slider. Its p.d. is large in bright light and small in the dark, just like input B of the burglar alarm switching from 1 to 0 when the beam is blocked.