There are three basic gates. AND outputs 1 only if every input is 1. OR outputs 1 if at least one input is 1. NOT has a single input and flips it. The other four gates are built from these: NAND is NOT-AND, NOR is NOT-OR, XOR (exclusive OR) outputs 1 when the inputs differ, and XNOR outputs 1 when they are the same.
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
NOT has only one input: NOT 0 = 1 and NOT 1 = 0.
A quick way to read the table: each NAND column is the AND column flipped, each NOR column is the OR column flipped, and XNOR is XOR flipped. If you remember AND, OR and XOR, you can derive the rest in seconds.
Worked example 1: AND
A = 1, B = 0. AND needs both to be 1, so the output is 0. A handy way to think of it: AND behaves like multiplication, 1 × 0 = 0.
Worked example 2: counting ones in the OR column
OR gives 0 only when both inputs are 0. So of the four rows, 3 give an output of 1.
Worked example 3: NAND
A = 1, B = 1. AND gives 1, and the NOT flips it, so NAND gives 0. This is the only row where NAND outputs 0.
Worked example 4: XOR
A = 1, B = 0. The inputs differ, so XOR gives 1. XOR behaves like adding the bits and keeping only the last binary digit.
Across its four rows, XOR outputs 1 exactly twice, in the two rows where the inputs differ.
Worked example 5: NOR
A = 0, B = 0. OR gives 0, and the NOT flips it, so NOR gives 1.