3.1.6Boolean Algebra & Logic Gates

XOR, NAND, NOR, XNOR gates

1,787 words8 min readdifficulty · medium5 backlinks

1. Building each gate from first principles

NAND — "NOT AND"

WHY this formula? NAND literally means "invert the AND". So take AND (ABA\cdot B), then NOT it (the overbar). Nothing more.

A B A·B NAND = AB\overline{A\cdot B}
0 0 0 1
0 1 0 1
1 0 0 1
1 1 1 0

NOR — "NOT OR"

WHY? Invert the OR. OR is 11 if any input is 11; inverting it means output is 11 only when nothing is 11.

A B A+B NOR = A+B\overline{A+B}
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0

XOR — "exclusive OR"

HOW do we derive that expression? Read the truth table and use Sum-Of-Products: write one AND term for each row that outputs 11, then OR them.

A B XOR Which row?
0 0 0
0 1 1 AB\overline{A}B
1 0 1 ABA\overline{B}
1 1 0

Rows that give 11: A=0,B=1A{=}0,B{=}1AB\overline{A}B, and A=1,B=0A{=}1,B{=}0ABA\overline{B}. OR them: AB=AB+ABA\oplus B = \overline{A}B + A\overline{B}

XNOR — "exclusive NOR" (equivalence)

WHY AB+ABAB + \overline{A}\,\overline{B}? Same SOP trick: the "same" rows are A=B=0A{=}B{=}0 (→ AB\overline{A}\,\overline{B}) and A=B=1A{=}B{=}1 (→ ABAB).

Figure — XOR, NAND, NOR, XNOR gates

2. Universality — WHY NAND (and NOR) rule the world

Deriving the three basics from NAND (from first principles):

  • NOT: tie both inputs together. A NAND A=AA=AA \text{ NAND } A = \overline{A\cdot A} = \overline{A}. ✅ Why this step? AA=AA\cdot A = A (idempotence), so the overbar gives A\overline A.
  • AND: NAND then NOT. AB=AB\overline{\overline{A\cdot B}} = A\cdot B. So AND = (A NAND B) fed into a NAND-as-NOT. ✅
  • OR: invert each input first, then NAND: AB=A+B\overline{\overline A \cdot \overline B} = A + B by De Morgan. ✅

That is why the chip industry can etch billions of identical NAND cells and wire them into anything.


3. Worked examples


4. Common mistakes (Steel-man + fix)


Recall Feynman: explain to a 12-year-old

Imagine two light switches.

  • XOR: the hallway light is ON only if the two switches disagree — one up, one down.
  • XNOR: light is ON only if they agree.
  • NAND: a lazy alarm that stays quiet only when both buttons are pressed together.
  • NOR: a picky alarm that beeps only when nobody touches any button. And the magic trick: with a big enough pile of the NAND alarm you can rebuild every other gate — like LEGO where one brick makes everything.

5. Recall

Flashcards

When is NAND output 0?
Only when all inputs are 1 (it is the inverse of AND).
When is NOR output 1?
Only when all inputs are 0 (inverse of OR).
XOR outputs 1 when...?
The inputs are different.
XNOR outputs 1 when...?
The inputs are the same (equivalence).
Boolean expression for XOR?
AB+AB\overline{A}B + A\overline{B}.
Boolean expression for XNOR?
AB+ABAB + \overline{A}\,\overline{B}.
How do you make NOT from one NAND?
Tie both inputs together: ANANDA=AA\,\text{NAND}\,A = \overline{A}.
Why is NAND called universal?
NOT, AND, OR can all be built from NAND alone, so any circuit can.
De Morgan for NOR?
A+B=AB\overline{A+B} = \overline{A}\cdot\overline{B}.
XOR of the bits 1,0,1 (chained) equals?
0 — an even number of 1s.
Difference between OR and XOR?
They differ only at (1,1): OR=1, XOR=0.
How to build OR from NAND?
Invert each input then NAND: AB=A+B\overline{\overline A \cdot \overline B} = A+B.

Connections

  • Boolean Algebra Laws — De Morgan's theorem powers all these conversions
  • AND, OR, NOT gates — the basics these are built from
  • Sum of Products (SOP) — how XOR/XNOR expressions are derived
  • Half Adder and Full Adder — XOR = sum bit, AND = carry
  • Parity Bits & Error Detection — chained XOR checks parity
  • Karnaugh Maps — simplifying gate expressions
  • Universal Gates — NAND/NOR completeness

Concept Map

invert AND

invert OR

derives

derives

inverse of

can build

can build

is

is

used in

core of

AND OR NOT basic gates

NAND: NOT of AND

NOR: NOT of OR

XOR: inputs different

XNOR: inputs same

Sum-Of-Products method

Universality

Real chips and adders

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, sabse pehle base gates hote hain AND, OR, NOT. Baaki sab inhi se bante hain. XOR ka matlab hai "dono inputs alag ho to output 1" — yaani difference detector. XNOR ulta hai: "dono same ho to 1" — equivalence check. Adder aur parity checker mein XOR hi dil ki tarah kaam karta hai.

NAND aur NOR actually AND aur OR ke upar ek bubble (NOT) laga dete hain. NAND ka output sirf tab 0 hota hai jab dono input 1 ho; NOR ka output sirf tab 1 hota hai jab dono input 0 ho. Yaad rakhne ka easy tareeka: N lagao to output ulta ho jaata hai.

Ab sabse important cheez — NAND aur NOR ko universal gates bolte hain. Iska matlab: sirf NAND se hi tum NOT, AND, OR — sab bana sakte ho. NOT banane ke liye dono input ek saath jod do (ANANDA=AA\,\text{NAND}\,A = \overline A). Isi wajah se real chips mein billions of identical NAND cells hote hain, kyunki ek hi type ki gate se poora processor ban jaata hai — cheap aur simple.

Ek common galti: log sochte hain A+B=A+B\overline{A+B} = \overline A + \overline B. Galat! De Morgan kehta hai operator flip hota hai: A+B=AB\overline{A+B} = \overline A \cdot \overline B. Yeh rule hi NAND/NOR conversions ka engine hai, isko pakka yaad rakhna.

Go deeper — visual, from zero

Test yourself — Boolean Algebra & Logic Gates

Connections