Home / Learn / Logic Gates

Logic Gates Explained: Symbols, Truth Tables and Boolean Rules

By Han · Published

Every digital system, from a pocket calculator to a modern processor, is built from a small set of logic gates. A logic gate is a circuit that takes one or more binary inputs (each either 0 or 1) and produces a single binary output according to a fixed rule. That rule is captured completely by the gate's truth table, which lists the output for every possible combination of inputs. Because there are only 0 and 1 to work with, an n-input gate has exactly 2n input combinations, so a two-input gate needs four rows and a three-input gate needs eight.

This page covers the seven gates you meet first in any digital electronics course: AND, OR, NOT, NAND, NOR, XOR, and XNOR. For each one you get the Boolean expression, the truth table, and the plain-language rule that tells you when the output is HIGH. You can type any of these into the CMOS Generator to see the transistor-level circuit and confirm the truth table for yourself.

AND, OR and NOT: the three primitives

AND, OR, and NOT are the three operations of Boolean algebra, and every other gate is a combination of them. The AND gate outputs 1 only when all of its inputs are 1, which is why it is written with the product symbol: Y = A·B. The OR gate outputs 1 when at least one input is 1, written with the sum symbol: Y = A + B. The NOT gate, also called an inverter, simply flips its single input: Y = A'.

ABA·B (AND)A+B (OR)
0000
0101
1001
1111

A useful way to remember them: AND behaves like multiplication of 0s and 1s, and OR behaves like addition that saturates at 1 (since 1 + 1 is still just 1 in Boolean algebra, not 2). The NOT gate has the shortest truth table of all: 0 becomes 1 and 1 becomes 0.

NAND and NOR: the inverted pair

NAND is AND followed by NOT, so its output is the complement of AND: it is 0 only when every input is 1. NOR is OR followed by NOT, so it is 1 only when every input is 0. On a gate symbol, this trailing inversion is drawn as a small bubble on the output.

AB(A·B)' (NAND)(A+B)' (NOR)
0011
0110
1010
1100

These two gates carry more weight than their simple definitions suggest. Each is functionally complete, meaning you can build any Boolean function using only NAND gates, or only NOR gates. Tie both inputs of a NAND together and you have an inverter; feed two NANDs in series and you recover AND; and so on. This is why real chips are dominated by NAND cells rather than by AND and OR gates, a point covered in detail on the NAND, NOR and SOP vs POS page.

XOR and XNOR: the equality gates

The exclusive-OR (XOR) gate outputs 1 when its two inputs are different, and 0 when they are the same. Its complement, the exclusive-NOR (XNOR), does the opposite: it outputs 1 when the inputs are equal, which is why XNOR is often called an equality or coincidence detector. The Boolean expressions are Y = A⊕B = A'B + AB' for XOR and Y = (A⊕B)' = A'B' + AB for XNOR.

ABA⊕B (XOR)(A⊕B)' (XNOR)
0001
0110
1010
1101

XOR is the workhorse of arithmetic and error-detection circuits. The sum bit of a half adder is exactly A⊕B, and a chain of XOR gates computes the parity of a data word, which is how simple parity checks catch single-bit transmission errors. Unlike the six other gates on this page, XOR and XNOR are not available as a single, compact static CMOS gate in the way NAND is; they are normally built from a handful of simpler gates or from transmission gates.

Combining gates into circuits

Individual gates become useful when you wire them together so that the output of one feeds the input of another. A Boolean expression such as Y = (A·B) + (B·C) + (A·C) describes exactly such a network: three AND gates feeding one OR gate. That particular expression is the majority function, whose output is 1 whenever at least two of its three inputs are 1. Reading an expression left to right, the operators inside the parentheses tell you the first layer of gates and the outer operator tells you the gate that combines them.

When you build a circuit this way, the truth table of the whole network is found by evaluating the expression for all 2n input combinations. Doing this by hand is slow and error-prone once you pass three variables, which is precisely what the CMOS Generator automates: enter the expression and it returns both the gate-level circuit and the complete truth table at once.

Frequently Asked Questions

How many basic logic gates are there?
There are three fundamental operations (AND, OR, NOT) and seven gates in common use once you add the composite gates NAND, NOR, XOR, and XNOR. Every other digital function can be built from these.
Which logic gate is universal?
Both NAND and NOR are universal, meaning any Boolean function can be built using only that one gate type. NAND is the more common choice in chip design because it is faster in CMOS.
What is the difference between OR and XOR?
OR outputs 1 when at least one input is 1, so it is also 1 when both inputs are 1. XOR outputs 1 only when the inputs differ, so it is 0 when both inputs are 1.
How do I find the truth table of a multi-gate circuit?
Write the Boolean expression for the circuit and evaluate it for every input combination, giving 2 to the power n rows for n inputs. The CMOS Generator does this automatically for any expression you enter.

Keep learning

References: R. L. Tocci and N. S. Widmer, Digital Systems: Principles and Applications; M. M. Mano and M. D. Ciletti, Digital Design; T. L. Floyd, Digital Fundamentals.