Logic Gates
Learn how AND, OR, NOT, XOR, NAND and NOR gates turn 1s and 0s into decisions, and how to find the output of a small circuit.
Advanced25 min18 problems
Definition
A logic gate is a tiny electronic circuit with one or two inputs and one output. Every input and every output is either 1 or 0:
- 1 = voltage on (high), which means true
- 0 = voltage off (low), which means false
Each gate performs one Boolean operation. Gates are the hardware version of AND, OR and NOT from the earlier lessons.
The two-input gates (inputs and , rows start with ):
| AND | OR | XOR | NAND | NOR | ||
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
The NOT gate (also called an inverter) has only one input and flips it: input 0 gives output 1, input 1 gives output 0.
How to remember them:
- AND: output 1 only when both inputs are 1
- OR: output 1 when at least one input is 1
- XOR (exclusive OR): output 1 when the inputs are different
- NAND (NOT AND): the opposite of AND, output 0 only when both inputs are 1
- NOR (NOT OR): the opposite of OR, output 1 only when both inputs are 0
Notation: engineers often write for AND, for OR and for NOT. They mean exactly the same as , and . XOR is written , NAND is and NOR is . Careful: here , because means OR.
A circuit connects gates: the output of one gate becomes an input of the next. To find the final output, go from the inputs to the output, one gate at a time.
The interactive table in this lesson uses and for the inputs and 1, 0 for the values. It draws the symbol of every gate, NAND and NOR included.
Try it now
Which gate gives output 1 only when both inputs are 1?
Interactive Visual
Truth Table
A ∧ B
| A | B | A ∧ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
1= True0= False
Interactive Sandbox
Expression Calculator
Try these:
History
No calculations yet
Practice Problems
18 problemsProblem 1 of 18
Easy
Which gate gives output 1 only when both inputs are 1?
Glossary
- Logic gate
- An electronic circuit that performs one Boolean operation on inputs of 1 and 0
- Input / output
- The signals going into a gate and the single signal coming out of it
- Circuit
- Gates connected by wires, where the output of one gate is an input of another
- Inverter
- Another name for the NOT gate, which flips 1 to 0 and 0 to 1
- XOR (exclusive OR)
- A gate whose output is 1 when its inputs are different, written
- Half adder
- A circuit of one XOR and one AND gate that adds two binary digits: ,
Formula Card
AND
1 only when both inputs are 1
OR
1 when at least one input is 1
NOT
Flips the input
XOR
1 when the inputs are different
NAND
Opposite of AND: 0 only when both inputs are 1
NOR
Opposite of OR: 1 only when both inputs are 0