Logic Gates and Truth Tables: AND, OR, NOT, NAND, NOR, XOR
Learn the seven basic logic gates with truth tables, symbols and expressions, the common TTL chips that hold them and how to read a gate level circuit.
Digital signals have two values
A digital circuit works with signals that have only two meaningful levels, called logic 0 and logic 1. In a TTL circuit powered from 5 V, an output at logic 0 is below 0.4 V and an output at logic 1 is above 2.4 V, usually near 3.4 V. A logic gate takes one or more of these inputs and makes an output that depends only on them.
A truth table lists the output of a gate for every possible input combination. With n inputs there are 2^n rows, so a two input gate has four rows. Truth tables are the plain way to say exactly what a circuit does.
The basic gates
| Gate | Expression | Output is 1 when | TTL chip |
|---|---|---|---|
| NOT | Y = A' | the input is 0 | 7404 (6 gates) |
| AND | Y = A · B | all inputs are 1 | 7408 (4 gates) |
| OR | Y = A + B | at least one input is 1 | 7432 (4 gates) |
| NAND | Y = (A · B)' | not all inputs are 1 | 7400 (4 gates) |
| NOR | Y = (A + B)' | all inputs are 0 | 7402 (4 gates) |
| XOR | Y = A ⊕ B | the inputs are different | 7486 (4 gates) |
| XNOR | Y = (A ⊕ B)' | the inputs are the same | 74266 (4 gates) |
The apostrophe means NOT. A dot means AND and a plus sign means OR. Remember that the plus sign is not addition here.
Truth tables of two input gates
This table shows the output of each gate for the four input pairs.
| A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
NAND is the opposite of AND on every row. NOR is the opposite of OR on every row. XNOR is the opposite of XOR.
Thinking about each gate
- AND is a series switch. Current flows only if A and B are both on.
- OR is a parallel switch. Current flows if either is on.
- NOT inverts. A double inversion returns the original value.
- XOR is a difference detector. With many inputs it gives 1 when an odd number of inputs are 1, so it is used to build parity checkers and adders.
- A NAND or NOR with its inputs tied together acts as a NOT gate.
An enable input shows how gates are used. An AND gate with A as the data and B as the enable passes A when B is 1, and gives 0 when B is 0. An OR gate with enable low passes the data, and gives 1 when the enable is high.
Reading a circuit
To find what a circuit does, write the output of each gate in terms of its inputs, from the left to the right. Then build the truth table by trying all input rows and following the signal.
Y = (A · B) + C' rows: ABC = 000 → Y = 1, 010 → 1, 100 → 1, 110 → 1, 001 → 0, 011 → 0, 101 → 0, 111 → 1
Check the last row: A = 1, B = 1 gives A · B = 1, so Y = 1 whatever C is. Check a middle row: A = 1, B = 0, C = 1 gives A · B = 0 and C' = 0, so Y = 0.
Real gates have delay
Gates are not instant. A standard 7400 series gate takes about 10 ns for its output to change, which is called the propagation delay. In a circuit with many gates in a chain, the delays add up. If two paths of different length meet at one gate, the output can show a short wrong pulse, called a glitch, before it settles.
For a lab, the delay is too small to see with switches and LEDs. It matters when you use a fast clock or when you look at the waveforms on an oscilloscope.
Try it in the virtual lab
SinBench has free 3D benches and interactive demos for this topic. Open one to try the ideas above with real instruments, no sign up needed.
Questions and answers
What is a truth table?
It is a table that lists the output of a circuit for every combination of inputs. A circuit with n inputs has 2^n rows.
What is the difference between OR and XOR?
OR gives 1 if any input is 1, including when both are 1. XOR gives 1 only when the inputs are different.
Which chip contains four 2 input NAND gates?
The 7400 contains four 2 input NAND gates in one 14 pin package. Pin 14 is the supply and pin 7 is ground.
How do you make a NOT gate from a NAND gate?
Connect both inputs of the NAND gate together. The output is then the opposite of the input.
Related topics
Boolean Algebra and De Morgan's Laws
Learn the Boolean identities, absorption and consensus, and De Morgan's laws, with worked simplification examples and truth table proofs you can check.
Digital Logic DesignNAND and NOR as Universal Gates
See why NAND and NOR are universal gates. Build NOT, AND, OR and XOR from NAND only and from NOR only, count the gates and use two level NAND logic.
Digital Logic DesignTTL Chips on a Breadboard: Power, Pin Numbers and Wiring Rules
A practical guide to wiring TTL chips on a breadboard: supply voltage, pin numbering, unused inputs, logic levels, LED resistors and common mistakes.