Sub topic 5
Building circuits from NAND or NOR only
This chapter assumes you know the basic gates (AND, OR, NOT), De Morgan's laws, and sum-of-products (SOP) and product-of-sums (POS) forms. You will see why NAND and NOR are called universal gates and how to convert any SOP or POS expression into a NAND-only or NOR-only circuit. You will also learn to count gates, which GATE questions often ask for.
Why NAND and NOR are universal
A gate set is universal if it can build every Boolean function. AND, OR and NOT are universal because every function has an SOP form. So if NAND alone can build NOT, AND and OR, then NAND alone is universal. The same argument works for NOR.
Recall the definitions: NAND(A, B) = (AB)' and NOR(A, B) = (A + B)'.
Basic gates from NAND
- NOT: tie both inputs together. NAND(A, A) = (AA)' = A'. Tying one input to 1 also works.
- AND: NAND followed by a NOT. This takes 2 gates.
- OR: NAND of the complemented inputs. NAND(A', B') = ((A')(B'))' = A + B by De Morgan. This takes 3 gates.
Basic gates from NOR
By duality the roles swap.
- NOT: NOR(A, A) = A'.
- OR: NOR followed by a NOT. This takes 2 gates.
- AND: NOR(A', B') = (A' + B')' = AB. This takes 3 gates.
| Function | NAND-only gates | NOR-only gates |
|---|---|---|
| NOT | 1 | 1 |
| AND | 2 | 3 |
| OR | 3 | 2 |
| NOR | 4 | 1 (native) |
| NAND | 1 (native) | 4 |
| XOR | 4 | 5 |
The four-gate NAND XOR is worth memorizing. Let t = NAND(A, B). Then A ⊕ B = NAND(NAND(A, t), NAND(B, t)). Check A = 1, B = 0. Here t = 1, NAND(A, t) = 0 and NAND(B, t) = 1, so the output is NAND(0, 1) = 1. That matches 1 ⊕ 0.
Two-level conversion: SOP to NAND-NAND
The key fact is that an AND-OR network and a NAND-NAND network compute the same function. Suppose F = P1 + P2 + ... + Pn, where each Pi is a product term. Applying De Morgan twice gives:
F = ((P1 + P2 + ... + Pn)')' = (P1' · P2' · ... · Pn')' = NAND(P1', P2', ..., Pn')
Each Pi' is just NAND of the literals in Pi. So the first level is one NAND per product term, and the second level is one NAND whose inputs are those outputs.
Worked example
Implement F = AB + C'D with NAND gates only.
- Minimal SOP is already given: two product terms.
- Level 1: NAND(A, B) for the first term. For the second term, C' must be produced first, with NAND(C, C), then NAND(C', D).
- Level 2: NAND the two level-1 outputs.
This takes 4 gates in total: three NANDs for the terms and output, plus one NAND acting as an inverter for C. The Verilog below uses gate primitives and mirrors the diagram exactly.
module f_nand(input a, input b, input c, input d, output f);
wire cn, p, q;
nand g1(cn, c, c); // C'
nand g2(p, a, b); // (AB)'
nand g3(q, cn, d); // (C'D)'
nand g4(f, p, q); // ((AB)'(C'D)')' = AB + C'D
endmoduleTwo-level conversion: POS to NOR-NOR
The dual statement holds. An OR-AND network equals a NOR-NOR network. Suppose F = S1 · S2 · ... · Sn, where each Si is a sum term. Then:
F = (S1' + S2' + ... + Sn')' = NOR(S1', ..., Sn')
Each Si' is NOR of the literals in Si. So the first level is one NOR per sum term, and the second level is one NOR.
Worked example
Implement F = (A + B)(C + D') with NOR gates only.
- Level 1: x = NOR(A, B) = (A + B)'. For the second sum, D' = NOR(D, D), then y = NOR(C, D') = (C + D')'.
- Level 2: F = NOR(x, y) = (A + B)(C + D').
Again the total is 4 gates. Quick check with A = 0, B = 0: x = 1, so F = NOR(1, y) = 0. The product (A + B)(C + D') is also 0, as expected.
Bubble-pushing procedure
For general networks, including multi-level ones, use this procedure.
- Draw the circuit with AND and OR gates, using the minimized expression.
- Group the gates into levels so that AND and OR alternate. Level 1 is nearest the inputs.
- For NAND-only, replace every gate (AND or OR) with a NAND. For NOR-only, replace every gate with a NOR.
- Every replaced gate changes the polarity of its output (a "bubble" is added). Compensate for each bubble. For an AND replaced by NAND, the output is complemented, so the next gate must see it as complemented. An OR gate whose inputs are all complemented acts as a NAND (De Morgan), so the alternating structure works.
- Wherever a signal does not pass through the expected number of bubbles, insert an inverter. This happens in two places: primary inputs that connect directly to a later level, and single-literal terms.
Gate counting and design choices
GATE questions often ask for the minimum number of NAND or NOR gates. A reliable method is to start from the minimal SOP (for NAND) or minimal POS (for NOR). Then count one gate per term, one output gate, and one inverter for each distinct complemented literal that appears.
Some edge cases follow.
- Complemented inputs: if the problem says complemented inputs are available, do not count inverters. If it says only true inputs are available, count them. Read the statement carefully.
- Shared inverters: if C' is needed in two product terms, build it once and fan it out. Count it once.
- Fan-in limits: a product term with more literals than the gate's inputs needs a multi-level tree. Because NAND is not associative, you cannot cascade NANDs to widen it. A 3-input AND from 2-input NANDs is NAND(NAND(NAND(A, B), C)...) only after adding inverters between stages. The simpler way is to build the AND from 2-input ANDs (each NAND plus a NAND inverter) and then use the result.
- Choosing NAND or NOR: SOP maps naturally onto NAND-NAND. POS maps naturally onto NOR-NOR. Converting a function to the other form is possible, but it often costs extra gates for inverters.
- Output inversion: NAND-NAND gives F directly. If you build NAND-NAND from a POS expression, you get a different function, so always check which form you started from.
Common mistakes
- Treating NAND(A, B, C) as if it equals NAND(NAND(A, B), C). It does not. The first is (ABC)', the second is ((AB)'C)' = AB + C'.
- Forgetting that NAND is not associative, so gates cannot be cascaded freely.
- Counting the inverter for C but not for D' when both are needed.
- Mixing up which two-level form belongs to which gate: NAND-NAND gives SOP, NOR-NOR gives POS.
Exercise
Using only 2-input NAND gates, what is the minimum number needed to build an OR gate, and what is the expression computed at the output?
Show answer
Three gates. Two NANDs act as inverters, giving A' and B'. A third NAND combines them: NAND(A', B') = ((A')(B'))' = A + B by De Morgan's law.
Exercise
Implement F = AB' + A'B (the XOR function) as a two-level NAND-NAND network when both true and complemented inputs are available. How many gates are required, and what changes if only true inputs are available?
Show answer
With both polarities available, the network needs 3 gates: NAND(A, B'), NAND(A', B), and a final NAND of the two outputs. If only true inputs are available, two more NAND gates are needed to make A' and B', so the total is 5 gates. The 4-gate XOR shown earlier in the chapter beats this because it reuses the shared NAND(A, B) in a multi-level structure.
Exercise
Convert F = (A + B')(C + D) into a NOR-only circuit assuming only true inputs are available. Count the gates.
Show answer
Level 1: x = NOR(A, B') = (A + B')' needs B' = NOR(B, B), and y = NOR(C, D) = (C + D)'. Level 2: F = NOR(x, y) = (A + B')(C + D). The gates are NOR(B, B), x, y and the output NOR, so 4 gates.