Skip to content

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)

WordsNAND(a, b)
ProgrammingNAND(a, b)
MathematicalNAND(a, b)
AlgebraNAND(a, b)

2 inputs: NAND(A, B)

NAND(A, B)
#ABf
0FALSEFALSETRUE
1FALSETRUETRUE
2TRUEFALSETRUE
3TRUETRUEFALSE
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)
NAND(A, B) NAND(A, B) A B f NAND
NAND(A, B) NAND(A, B) A B f NAND

3 inputs: NOT (A AND B AND C): NOT (A AND B AND C)

NOT (A AND B AND C)
#ABCf
0FALSEFALSEFALSETRUE
1FALSEFALSETRUETRUE
2FALSETRUEFALSETRUE
3FALSETRUETRUETRUE
4TRUEFALSEFALSETRUE
5TRUEFALSETRUETRUE
6TRUETRUEFALSETRUE
7TRUETRUETRUEFALSE
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)
NOT (A AND B AND C) NOT (A AND B AND C) A B C f NOT AND
NOT (A AND B AND C) NOT (A AND B AND C) A B C f NOT AND

4 inputs: NOT (A AND B AND C AND D): NOT (A AND B AND C AND D)

NOT (A AND B AND C AND D)
#ABCDf
0FALSEFALSEFALSEFALSETRUE
1FALSEFALSEFALSETRUETRUE
2FALSEFALSETRUEFALSETRUE
3FALSEFALSETRUETRUETRUE
4FALSETRUEFALSEFALSETRUE
5FALSETRUEFALSETRUETRUE
6FALSETRUETRUEFALSETRUE
7FALSETRUETRUETRUETRUE
8TRUEFALSEFALSEFALSETRUE
9TRUEFALSEFALSETRUETRUE
10TRUEFALSETRUEFALSETRUE
11TRUEFALSETRUETRUETRUE
12TRUETRUEFALSEFALSETRUE
13TRUETRUEFALSETRUETRUE
14TRUETRUETRUEFALSETRUE
15TRUETRUETRUETRUEFALSE
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)
NOT (A AND B AND C AND D) NOT (A AND B AND C AND D) A B C D f NOT AND
NOT (A AND B AND C AND D) NOT (A AND B AND C AND D) A B C D f NOT AND

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

Tools

Practice

See also

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.