NAND gate: truth table for 2, 3 and 4 inputs, universal gate
NAND is an AND followed by a NOT: NAND(A, B) is FALSE only when both inputs are TRUE. It is a universal gate, because NOT, AND and OR can all be built from it.
The two-input table is the AND table inverted: three TRUE rows and one FALSE row, the last. For three and four inputs the language writes the gate as NOT (A AND B AND C) and NOT (A AND B AND C AND D), and the tables below show them: a single FALSE row, where every input is TRUE. NAND itself is accepted only in function form with exactly two operands, NAND(A, B); the infix A NAND B is rejected with a repair, and NAND(A, B, C) is rejected as the wrong arity.
By De Morgan, NAND(A, B) is NOT A OR NOT B: at least one input fails. That is why NAND is easy to confuse with NOR (NOT A AND NOT B, both fail); the pitfall page on “neither nor” shows the two rows on which they differ. In a diagram the gate is the AND shape with a bubble on its output.
Universality is what makes NAND important. NAND(A, A) is NOT A; NAND(NAND(A, B), NAND(A, B)) is A AND B; NAND(NAND(A, A), NAND(B, B)) is A OR B. Each construction is proved on its own law page, and the NAND-only converter applies them to any expression, reports the gate count, and checks the result exactly against the original. The worked examples show the classic four-gate XOR and the majority function built from NAND alone.
Accepted spellings
NAND(a, b)
NAND(a, b)NAND(a, b)NAND(a, b)NAND(a, b)2 inputs: NAND(A, B)
| # | A | B | f |
|---|---|---|---|
| 0 | FALSE | FALSE | TRUE |
| 1 | FALSE | TRUE | TRUE |
| 2 | TRUE | FALSE | TRUE |
| 3 | TRUE | TRUE | FALSE |
Beginnerf is true exactly when A and B are not both true.
In every other case, f is false.
About the operators:
- NAND (“not and”) is false only when both parts are true.
Intermediatef is true exactly when A and B are not both true.
In every other case, f is false.
Advancedf is true exactly when A and B are not both true [Sheffer stroke ↑ (NAND)].
In every other case, f is false.
Formal notation: NAND(A, B)
3 inputs: NOT (A AND B AND C): NOT (A AND B AND C)
| # | A | B | C | f |
|---|---|---|---|---|
| 0 | FALSE | FALSE | FALSE | TRUE |
| 1 | FALSE | FALSE | TRUE | TRUE |
| 2 | FALSE | TRUE | FALSE | TRUE |
| 3 | FALSE | TRUE | TRUE | TRUE |
| 4 | TRUE | FALSE | FALSE | TRUE |
| 5 | TRUE | FALSE | TRUE | TRUE |
| 6 | TRUE | TRUE | FALSE | TRUE |
| 7 | TRUE | TRUE | TRUE | FALSE |
Beginnerf is true exactly when the following condition does not hold:
1. all of A, B, and C are true
In every other case, f is false.
About the operators:
- NOT reverses a value: true becomes false and false becomes true.
- AND is true only when all of its parts are true.
Intermediatef is true exactly when the following condition does not hold:
1. all of A, B, and C are true
In every other case, f is false.
Advancedf is true exactly when the following condition does not hold [negation ¬]:
1. all of A, B, and C are true [conjunction ∧]
In every other case, f is false.
Formal notation: ¬(A ∧ B ∧ C)
4 inputs: NOT (A AND B AND C AND D): NOT (A AND B AND C AND D)
| # | A | B | C | D | f |
|---|---|---|---|---|---|
| 0 | FALSE | FALSE | FALSE | FALSE | TRUE |
| 1 | FALSE | FALSE | FALSE | TRUE | TRUE |
| 2 | FALSE | FALSE | TRUE | FALSE | TRUE |
| 3 | FALSE | FALSE | TRUE | TRUE | TRUE |
| 4 | FALSE | TRUE | FALSE | FALSE | TRUE |
| 5 | FALSE | TRUE | FALSE | TRUE | TRUE |
| 6 | FALSE | TRUE | TRUE | FALSE | TRUE |
| 7 | FALSE | TRUE | TRUE | TRUE | TRUE |
| 8 | TRUE | FALSE | FALSE | FALSE | TRUE |
| 9 | TRUE | FALSE | FALSE | TRUE | TRUE |
| 10 | TRUE | FALSE | TRUE | FALSE | TRUE |
| 11 | TRUE | FALSE | TRUE | TRUE | TRUE |
| 12 | TRUE | TRUE | FALSE | FALSE | TRUE |
| 13 | TRUE | TRUE | FALSE | TRUE | TRUE |
| 14 | TRUE | TRUE | TRUE | FALSE | TRUE |
| 15 | TRUE | TRUE | TRUE | TRUE | FALSE |
Beginnerf is true exactly when the following condition does not hold:
1. all of A, B, C, and D are true
In every other case, f is false.
About the operators:
- NOT reverses a value: true becomes false and false becomes true.
- AND is true only when all of its parts are true.
Intermediatef is true exactly when the following condition does not hold:
1. all of A, B, C, and D are true
In every other case, f is false.
Advancedf is true exactly when the following condition does not hold [negation ¬]:
1. all of A, B, C, and D are true [conjunction ∧]
In every other case, f is false.
Formal notation: ¬(A ∧ B ∧ C ∧ D)
The common slip
Reading NAND as “not A and not B”. That is NOR. NAND means “not both”: it is TRUE whenever at least one input is FALSE, so it has three TRUE rows, not one.
Questions
Why does the parser insist on NAND(A, B) with two operands?
Because NAND is not associative: NAND(NAND(A, B), C) and NAND(A, NAND(B, C)) are different functions, so an unbracketed chain would have no agreed meaning. For more inputs write NOT (A AND B AND C).
How many NAND gates does each basic gate cost?
NOT needs one, AND two, OR three. XOR needs four in the classic hand-drawn circuit; the engine's mechanical construction uses more, and the worked example proves both equivalent.
Related
Guides
Worked examples that use it
Laws
- NAND elimination: NAND(A, B) = NOT (A AND B)
- NOT from NAND: NOT A = NAND(A, A)
- AND from NAND gates: A AND B = NAND(NAND(A, B), NAND(A, B))
- OR from NAND gates: A OR B = NAND(NAND(A, A), NAND(B, B))
Tools
- Truth table generator: any Boolean expression, up to 12 variables, with intermediate columns
- Logic circuit generator: Boolean expression to gate diagram (SVG)
Practice
See also
- NAND elimination: NAND(A, B) = NOT (A AND B)
- NOT from NAND: NOT A = NAND(A, A)
- AND from NAND gates: A AND B = NAND(NAND(A, B), NAND(A, B))
- OR from NAND gates: A OR B = NAND(NAND(A, A), NAND(B, B))
- De Morgan's laws: NOT (A AND B) = NOT A OR NOT B, with proof and examples
- NOR gate: truth table for 2, 3 and 4 inputs, universal gate
- “Neither A nor B” is NOT A AND NOT B
- XOR with four NAND gates, verified equivalent
- Majority of three with NAND gates only
- NAND-only and NOR-only converter with equivalence proof
Operators and gates
Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.