The short answer: logic gates are the building blocks of digital circuits. The basic gates are AND, OR and NOT; the derived gates are NAND, NOR, XOR and XNOR. NAND and NOR are called universal gates because any logic function can be built using only one of them, which is one reason CMOS standard-cell libraries rely so heavily on them.
This post combines my older posts on basic gates, universal gates and realising functions with gates. Here is everything you need, in one place.
- Truth tables for every gate
- What each gate is good for
- Why NAND and NOR are universal
- Realising a function with gates
- Gates in Verilog
Table of Contents
Part 1: Truth tables for every gate
| 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 simply inverts its single input: 0 becomes 1 and 1 becomes 0.
Part 2: What each gate is good for
- AND: “all conditions true”, for example enabling a write only when valid and ready are both high.
- OR: “any condition true”, for example combining interrupt sources.
- XOR: “inputs differ”. Used in adders, parity and comparators.
- XNOR: “inputs equal”. Used in equality comparators.
- NAND and NOR: the natural gates in CMOS, and universal.
Part 3: Why NAND and NOR are universal

Because NOT, AND and OR can each be made from NAND gates alone, any Boolean function can be too. The same is true of NOR, by duality. In CMOS, a NAND or NOR gate needs fewer transistors than an AND or OR (which is just a NAND or NOR plus an inverter), so they are the most efficient building blocks.
Part 4: Realising a function with gates
To build F = A·B + C·D: in AND-OR form you need two AND gates and an OR gate. Using De Morgan, the same function is a two-level NAND-NAND circuit: NAND each product term, then NAND the results. F = ((A·B)’ · (C·D)’)’. This NAND-NAND form is how sum-of-products logic is often implemented in CMOS.
Part 5: Gates in Verilog
// Continuous assignments: the usual way to describe gates
assign y_and = a & b;
assign y_or = a | b;
assign y_not = ~a;
assign y_nand = ~(a & b);
assign y_nor = ~(a | b);
assign y_xor = a ^ b;
assign y_xnor = ~(a ^ b);
In real designs you write the logic and let synthesis choose the gates from the standard-cell library.
Practise this on VLSI Forge
I built VLSI Forge so you can write RTL in your browser, run it on a real simulator and check every signal in the waveform. Free, nothing to install.
FAQ
Why are NAND and NOR called universal gates?
Because any logic function, including NOT, AND and OR, can be built using only NAND gates, or only NOR gates.
Is XOR a basic gate?
It is usually called a derived gate, since it can be built from AND, OR and NOT, but it is so useful that every library includes it.
Which gate is fastest in CMOS?
Simple inverting gates like NAND, NOR and the inverter, because they need only one stage of transistors.
How many NAND gates make an XOR?
Four.
