Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
    • Classic Brain Teasers
    • Probability Puzzles
    • Digital Logic Puzzles
      • Build XOR Using Only 2:1 MUXes
      • AND/OR/NOT from One 2:1 MUX Each
      • Minimum NAND Gates for XOR
      • Overlapping 1011 Sequence Detector
      • Mod-6 Counter Behavior Check
      • Metastability MTBF Improvement Estimate
    • Debugging Riddles
    • Logic & Aptitude Puzzles: Tricky Q&A
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Digital Logic Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Logic & Aptitude Puzzles
  4. Digital Logic Puzzles
  5. Minimum NAND Gates for XOR

VLSI DV Interview Puzzles · All levels

Minimum NAND Gates for XOR

Implement XOR using only 2-input NAND gates. What is the minimum number of NAND gates and one valid construction?

On this page

    Puzzle

    Difficulty: Medium · Puzzle 3 of 6 · Topic: Digital Logic Puzzles

    Implement XOR using only 2-input NAND gates. What is the minimum number of NAND gates and one valid construction?

    Code

    design.sv
    1
    2
    3
    4
    n1 = ~(A & B);
    n2 = ~(A & n1);
    n3 = ~(B & n1);
    Y  = ~(n2 & n3); // XOR

    Hint

    Use the canonical 4-NAND XOR network.

    Step-by-step solution

    Diagram
    1) Create n1 = NAND(A,B) = ~(A&B).
    2) Create n2 = NAND(A,n1) and n3 = NAND(B,n1).
    3) Final output Y = NAND(n2,n3).
    4) Substituting shows Y = A^B.
    5) This uses 4 NAND gates, which is the known minimum for XOR with 2-input NAND-only logic.

    Answer

    Answer: Minimum is 4 NAND gates.

    Why candidates get it wrong

    Claiming 3 NANDs works; it cannot realize full XOR truth table.

    Interviewer follow-up

    What is the minimum NAND count for XNOR?

    Related topics

    • Back to Digital Logic Puzzles

    • Logic & Aptitude Puzzles section

    Previous

    169 / 210

    Next: Overlapping 1011 Sequence Detector

    Up next

    Up nextOverlapping 1011 Sequence Detector

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Build XOR Using Only 2:1 MUXes
    • Mod-6 Counter Behavior Check
    • Metastability MTBF Improvement Estimate