Skip to content
Explainer · Logic Gates

Logic Gates Explained: AND, OR, NOT, XOR and NAND

How logic gates turn 1s and 0s into decisions, how to read truth tables, why NAND can build every other gate, and how De Morgan's laws connect them.

4 min readPublished

Every app, game and website you use runs on circuits that do almost nothing but answer yes or no questions, very quickly and in huge numbers. The building blocks are logic gates. Once you can read seven simple rules, you can follow how a calculator adds numbers or how a chip stores a single bit.

Bits, signals and truth tables

In the simplest model of a digital circuit, a signal can be in one of two states: 1 (high, on, true) or 0 (low, off, false). A single value like that is a bit. Real chips use ranges of voltage and need a little time to switch, but the two-state picture is the one designers reason with.

A logic gate takes one or more input bits and produces one output bit by a fixed rule. To describe that rule completely you list every possible input combination and the output for each. That list is a truth table. With two inputs there are only four rows (00, 01, 10, 11), so a gate's whole personality fits in a tiny table.

The three basic gates

AND

AND outputs 1 only when every input is 1. Picture two switches wired one after the other: the lamp lights only if both are closed. Boolean algebra writes it like multiplication, A · B, which makes sense because 1 × 1 is the only product that equals 1.

OR

OR outputs 1 when at least one input is 1. Picture two switches wired side by side: closing either one lights the lamp. It is written like addition, A + B, with the rule that 1 + 1 is still just 1. An OR output is 0 in only one row, where both inputs are 0.

NOT

NOT, also called an inverter, has a single input and flips it: 0 becomes 1 and 1 becomes 0. It is written with a bar or a prime, Ā or A′. Invert twice and you are back where you began.

XOR: the "different" detector

XOR (exclusive OR) outputs 1 when its two inputs differ and 0 when they match. That is almost like OR, except the 1 and 1 row gives 0 instead of 1.

XOR matters because it is the heart of binary addition. Add two single bits: 0 + 0 is 0, 0 + 1 is 1, 1 + 0 is 1, and 1 + 1 is 10 in binary, which is a sum digit of 0 and a carry of 1. The sum digit follows the XOR table exactly, while the carry follows the AND table. Put one XOR and one AND side by side and you have a circuit that adds two bits, the seed of every adder inside a processor.

NAND, NOR and XNOR: the inverted gates

Put a NOT after a gate and you get its inverted twin:

  • NAND is AND followed by NOT. It outputs 0 only when all inputs are 1.
  • NOR is OR followed by NOT. It outputs 1 only when all inputs are 0.
  • XNOR is XOR followed by NOT. It outputs 1 when the inputs are the same, so it works as a one-bit equality check.

Why NAND is "universal"

NAND on its own is functionally complete: you can build NOT, AND, OR and every other gate using nothing but NAND gates. Tie the two inputs of a NAND together and you have a NOT. NAND followed by that NOT gives AND. A little more wiring gives OR. NOR is universal in the same way.

That is not just a puzzle. Making one kind of gate over and over can be simpler and cheaper than stocking many kinds, so the fact appears constantly in real chip design.

Live lab Live logic lab. Flip the inputs and follow the signal through each gate. Open the full Logic Gates lab →

De Morgan's laws: pushing a NOT through

Two laws let you swap AND and OR by moving an inversion across them:

  • inverting an AND gives the OR of the two inverted inputs;
  • inverting an OR gives the AND of the two inverted inputs.

In words: "not both" is the same as "at least one is missing", and "not either" is the same as "both are missing". You can test the laws by writing out the four rows of each side and seeing that the columns match.

These laws are the reason NAND and NOR are universal. They let you rewrite any expression using only one kind of gate, and they are also a handy tool for simplifying a messy circuit into a smaller one.

Mistakes to avoid

  • Mixing up OR and XOR. They differ in exactly one row: both inputs 1.
  • Reading NAND as "not AND" in words only. Check the table: NAND is 1 almost everywhere and 0 only when all inputs are 1.
  • Forgetting that wires have no memory. A gate's output depends only on its present inputs. Remembering values needs a feedback loop, which is the next topic after these basics.
  • Treating the 0/1 model as the physical truth. Real circuits have timing and noise; the model hides them on purpose.

How to explore this in the lab

The Logic Gates lab lets you drag gates onto a board, wire them together and flip input switches to watch signals travel. A good order through the free first world:

  1. Meet signals and tables in Bits, Signals & Truth Tables.
  2. Build the conjunction in The AND Gate.
  3. Find the "different" detector in The XOR Gate.
  4. Prove universality in NAND, the Universal Gate.
  5. Rewrite expressions with De Morgan's Laws.

The lab is a simplified teaching model in which gates switch instantly, which keeps the logic clean, so treat it as a way to understand the ideas rather than to design hardware.

Key takeaways
  • A gate maps input bits to an output bit, and a truth table lists every case.
  • AND needs all inputs 1, OR needs at least one, NOT flips, XOR means "different".
  • One XOR plus one AND adds two bits: sum and carry.
  • NAND alone can build every other gate, and De Morgan's laws show why.
Free lesson · Logic Gates

Bits, Signals & Truth Tables

Everything a computer does is 1s and 0s. About 5 minutes. Free, no account, runs in your browser.

Start the free lesson

Report a mistake

What is wrong?
0 / 2000 · at least 10 characters
Sent along with your report
  • Page
  • About Logic Gates Explained: AND, OR, NOT, XOR and NAND · logic-gates-explained-and-or-not-xor-nand
Plus your browser type. Reports go to our support system; see the privacy notice.

Simulations on Novareka are teaching models, simplified on purpose. They show how an idea behaves; they are not a substitute for professional, medical or engineering advice.