Skip to main content

XOR gate using minimum NAND gates

Short answer

XOR is built with four 2-input NAND gates: G1 = NAND(A,B), G2 = NAND(A,G1), G3 = NAND(B,G1), and output Y = NAND(G2,G3). This yields A ⊕ B.

Construct two input XOR gate using minimum number of 2-input NAND gates only.

An XOR gate gives Y=A⊕B=ABˉ+AˉBY = A \oplus B = A\bar B + \bar A B. With NAND gates only, the minimum is four 2-input NAND gates.

Derivation

Y=ABˉ+AˉB=AAˉ+ABˉ+BAˉ+BBˉ(adding AAˉ=BBˉ=0)=A(Aˉ+Bˉ)+B(Aˉ+Bˉ)=A AB‾+B AB‾=A AB‾‾⋅B AB‾‾‾(De Morgan)\begin{aligned} Y &= A\bar B + \bar A B \\ &= A\bar A + A\bar B + B\bar A + B\bar B \quad (\text{adding } A\bar A = B\bar B = 0) \\ &= A(\bar A + \bar B) + B(\bar A + \bar B) \\ &= A\,\overline{AB} + B\,\overline{AB} \\ &= \overline{\overline{A\,\overline{AB}} \cdot \overline{B\,\overline{AB}}} \quad (\text{De Morgan}) \end{aligned}

So the gates are:

  • G1=AB‾G_1 = \overline{AB}
  • G2=A⋅G1‾G_2 = \overline{A \cdot G_1}
  • G3=B⋅G1‾G_3 = \overline{B \cdot G_1}
  • Y=G2⋅G3‾Y = \overline{G_2 \cdot G_3}

Circuit

 A --+-----------------|‾‾\
     |                 |G2 |o--+
     |  |‾‾\      +----|__/    |   |‾‾\
     +--|G1 |o----+            +---|G4 |o-- Y
     +--|__/      +----|‾‾\    +---|__/
     |                 |G3 |o--+
 B --+-----------------|__/

Verification

ABG1G_1G2G_2G3G_3Y
001110
011101
101011
110110

Output Y is 1 only when the inputs differ, which is the XOR function. Total: 4 NAND gates.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Digital Logic chapter 2 questions →