Logic Gates & Boolean Basics

Everything the phone in your pocket does — decode a video, check a password, add two numbers a billion times a second — is built from a handful of tiny electrical switches that answer just one kind of question: is this true or false? A wire is either near 5 V5\ \text{V} (call it 1, or TRUE) or near 0 V0\ \text{V} (call it 0, or FALSE). Nothing in between counts. That brutal simplicity is the whole secret of digital electronics: two voltages, and rules for combining them. The rules were not invented by an engineer. In the 1840s the self-taught English mathematician George Boole wrote down an algebra in which variables take only the values true and false and the operations are AND, OR and NOT. For ninety years it sat in logic books as a curiosity. Then in 1937 a 2121-year-old MIT graduate student named Claude Shannon noticed something nobody had: a network of on/off relays obeys Boole's algebra exactly. A switch is a variable; switches in series are AND; switches in parallel are OR. In one master's thesis he fused abstract logic with electrical circuits and made the digital computer conceivable. This article is that thesis at school level. We meet the three basic logic gates — OR, AND, NOT — with their truth tables and symbols; we build them for real from the diodes and transistors of the previous chapters; we combine them into NOR and NAND and discover the astonishing fact that either one of those two gates, alone, can build every possible circuit. And we learn just enough Boolean algebra to simplify a messy circuit into a tidy one — the exam skill that turns a page of gates into a single line. No calculus, only the algebra of true and false.

Key takeaways
  • A logic gate is a switch-built circuit that outputs a 1 or 0 according to a fixed rule. Voltage HIGH (∼5 V\sim 5\ \text{V}) means logic 11; voltage LOW (∼0 V\sim 0\ \text{V}) means logic 00. There is nothing in between.
  • Three gates are basic. OR gives Y=A+BY=A+B (output 11 if any input is 11); AND gives Y=A⋅BY=A\cdot B (output 11 only if all inputs are 11); NOT gives Y=AˉY=\bar A (it inverts).
  • A truth table lists the output for every input combination. With nn inputs there are 2n2^{n} rows — 44 rows for two inputs, 88 for three.
  • Real gates are made from diodes and transistors. Diodes steer current for OR and AND; a transistor driven between cutoff and saturation makes the inverting NOT.
  • NOR and NAND are a basic gate plus a NOT. NOR=A+B‾\text{NOR}=\overline{A+B}, NAND=A⋅B‾\text{NAND}=\overline{A\cdot B}. De Morgan's theorems relate them: A+B‾=Aˉ⋅Bˉ\overline{A+B}=\bar A\cdot\bar B and A⋅B‾=Aˉ+Bˉ\overline{A\cdot B}=\bar A+\bar B.
  • NAND and NOR are universal. Using nothing but NAND gates (or nothing but NOR gates) you can build NOT, AND, OR and therefore any digital circuit at all — which is why real chips are seas of one gate type.
  • Key idea: a logic gate turns the true/false algebra George Boole wrote in 1847 into hardware — Claude Shannon's 1937 insight — so that OR, AND and NOT (and the universal NAND/NOR) built from diodes and transistors can compute anything, one binary decision at a time.
The core insight

A logic gate is an electronic switch network whose output voltage is HIGH (11) or LOW (00) according to a fixed Boolean rule of its inputs; the three basic gates OR (A+BA+B), AND (A⋅BA\cdot B) and NOT (Aˉ\bar A) — realized from diodes and transistors and captured by 2n2^{n}-row truth tables — combine into NAND and NOR, each of which is universal, able on its own to build every logic function.

Where this lives today

Every digital device is a city of logic gates. A modern processor wires tens of billions of transistors into gates, each doing exactly what this article describes — reading two-valued inputs, forcing a two-valued output — a few billion times a second. Adders built from XOR and AND gates do the arithmetic; latches and flip-flops built from cross-coupled NAND or NOR gates hold the bits of memory. Because NAND is universal and cheap to fabricate, whole chips are laid down as uniform NAND arrays and personalised by their wiring — and NAND flash memory, the storage in every phone and SSD, takes its name from the gate structure of its cells. The very idea that a machine can reason — that "if this and not that, then act" can be a voltage — is Shannon's, and it now underlies not just computers but every controller in a car, a pacemaker, or a spacecraft. The next article is the numerical gym where these truth tables meet the band-gap, mass-action and rectifier numbers of the whole chapter.

The physical picture

Digital electronics makes one radical decision: it throws away all voltages except two. Inside a logic chip a wire is not allowed to loiter at 2.7 V2.7\ \text{V} or 3.9 V3.9\ \text{V}; the circuit forces it either near the supply rail (HIGH) or near ground (LOW), and reads everything in between as noise to be squeezed out. We label the HIGH state 1 and the LOW state 0 — but the labels are a convention, not a measurement. In classic TTL (transistor–transistor logic) chips the rail is +5 V+5\ \text{V}, so 1≈5 V1\approx 5\ \text{V} and 0≈0 V0\approx 0\ \text{V}; modern low-power chips use 3.3 V3.3\ \text{V} or less. What matters is only that there are exactly two allowed states, because two states is the minimum you need to say yes or no, true or false — one bit of information. Once a wire carries a truth value, a circuit that combines wires is doing logic. Recall the transistor of the previous article as a switch: driven hard into saturation it is ON (a closed switch, output pulled LOW), starved into cutoff it is OFF (an open switch, output floats HIGH). Recall the diode as a one-way valve. A logic gate is nothing more than a small, deliberate arrangement of these switches and valves whose output voltage is HIGH or LOW according to a fixed rule applied to its input voltages. Shannon's discovery was that these rules are precisely Boole's AND, OR and NOT — so a circuit designer can reason about hardware with pencil-and-paper algebra instead of a voltmeter.

Figure
The five gates a student must recognise on sight, each drawn with its standard symbol, its Boolean expression, and its one-line rule — OR fires on any input, AND needs all inputs, NOT inverts, and NAND and NOR are AND and OR each followed by an inverting bubble
The gate chart — symbol, Boolean expression, and the rule in words OR Y = A + B 1 if ANY input is 1 AND Y = A · B 1 only if ALL inputs are 1 NOT Y = A̅ inverts the single input NAND Y = A · B (bar) AND then invert · UNIVERSAL NOR Y = A + B (bar) OR then invert · UNIVERSAL the small bubble on a symbol always means an inverting output — NOT, NAND and NOR all carry one

The three basic gates: OR, AND, NOT

A gate's behaviour is completely fixed once you list its output for every possible set of inputs. That list is the truth table, and it is the single most important object in this chapter — draw it correctly and every question falls out of it. Because each input is a bit that can be 00 or 11, a gate with nn inputs has

N=2 n(1)N = 2^{\,n} \qquad (1)

rows in its truth table. where: nn is the number of inputs and NN is the number of distinct input combinations. The physical reading: two inputs give 22=42^{2}=4 rows, three inputs give 23=82^{3}=8 rows, and the count doubles with every wire you add — which is exactly why circuits with many inputs grow complicated so fast. (A related count worth knowing: with two inputs there are 24=162^{4}=16 different truth tables you could fill in, so there are exactly sixteen possible two-input gates — but only a few have names.)

The OR gate answers "is at least one input true?" Its Boolean expression is Y=A+BY=A+B, read "A OR B," where the ++ sign is logical OR, not ordinary addition (so 1+1=11+1=1, not 22). It outputs 00 only when every input is 00.

ABY = A + B
000
011
101
111

The AND gate answers "are all inputs true?" Its expression is Y=A⋅BY=A\cdot B, read "A AND B," where the dot is logical AND (which happens to agree with ordinary multiplication for single bits: 1⋅1=11\cdot 1=1, 1⋅0=01\cdot 0=0). It outputs 11 only when every input is 11.

ABY = A · B
000
010
100
111

The NOT gate (also called an inverter) takes a single input and flips it: Y=AˉY=\bar A, read "NOT A" or "A bar." It is the only basic gate with one input, and its truth table has just 21=22^{1}=2 rows.

AY = A̅
01
10

These three are functionally complete: any logic function whatsoever can be written with OR, AND and NOT alone. That is why a Boolean expression like Y=A⋅Bˉ+Aˉ⋅BY = A\cdot\bar B + \bar A\cdot B (which, you can check, is the "exactly one input is 1" or XOR rule) is a perfectly good recipe for a circuit — it says "build two AND gates, two inverters, and an OR gate, and wire them thus."

Building gates from diodes and transistors

Symbols and tables are the logic; the previous two articles gave us the hardware to make them real. A diode passes current one way and blocks the other; a transistor, driven hard, snaps between a closed switch (saturation) and an open one (cutoff). Combine them and the abstract gates become circuits you could solder. The NOT gate is a single transistor in common-emitter, exactly the "transistor as a switch" of the last article. Tie the output through a load resistor to the supply VCC=5 VV_{CC}=5\ \text{V} and feed the input to the base through a resistor. When the input is HIGH (5 V5\ \text{V}), base current drives the transistor into saturation; it conducts hard and pulls the output down to the saturation voltage VCE(sat)≈0.2 VV_{CE(\text{sat})}\approx 0.2\ \text{V} — a LOW. When the input is LOW (0 V0\ \text{V}), no base current flows, the transistor is in cutoff (open switch), and the output floats up to VCC=5 VV_{CC}=5\ \text{V} — a HIGH. HIGH in gives LOW out, LOW in gives HIGH out: that is Y=AˉY=\bar A, and it is why the common-emitter stage's built-in 180∘180^\circ inversion is the NOT gate. The OR and AND gates can be made from two diodes. In diode OR, the two inputs feed the anodes of two diodes whose cathodes join at the output, which is tied to ground through a resistor. If either input is HIGH, its diode conducts and lifts the output to one diode-drop below the input, 5−0.7=4.3 V5-0.7=4.3\ \text{V} — comfortably a HIGH; only if both inputs are LOW does the output stay at 0 V0\ \text{V}. In diode AND, the inputs feed the cathodes and the common anode is pulled up to +5 V+5\ \text{V} through a resistor. If either input is LOW, its diode conducts and clamps the output down to 0+0.7=0.7 V0+0.7=0.7\ \text{V} — a LOW; only when both inputs are HIGH does no diode conduct and the output rise to +5 V+5\ \text{V}, a HIGH.

Figure
Three real gate circuits — a transistor inverter that pulls its output to about 0.2 volts when the input is high and up to 5 volts when the input is low, a two-diode OR whose output rises when either input is high, and a two-diode AND whose output stays low unless both inputs are high
Gates made from the diode and the transistor NOT — one transistor +5 V R_L A Y = A̅ A high → saturate → Y≈0.2 V A low → cutoff → Y=5 V OR — two diodes A B Y R any input high → Y = 5−0.7 = 4.3 V both low → Y = 0 V AND — two diodes +5 V R A B Y any input low → Y = 0.7 V both high → Y = 5 V diodes steer current for OR and AND; the transistor's inversion gives NOT — the three basics from parts you already know
Derivation AWhy a transistor inverter really computes NOT — the two voltage states

The goal is to show, using only the switching behaviour of a single common-emitter transistor and the diode/transistor facts from the previous articles, that the circuit output takes exactly the two values a NOT gate demands — a genuine LOW when the input is HIGH and a genuine HIGH when the input is LOW — and to pin the actual voltages so the "0" and "1" are not just labels. We take VCC=5 VV_{CC}=5\ \text{V}, a silicon transistor, and drive the base hard enough to saturate on a HIGH input.

Step 1. Input HIGH, A=5 VA=5\ \text{V}. The base–emitter junction is forward biased well past its 0.7 V0.7\ \text{V} knee, so base current flows and, with the base resistor chosen for saturation, the collector current is as large as the load allows. The transistor is a closed switch from collector to emitter: the collector sits at the saturation voltage VCE(sat)≈0.2 VV_{CE(\text{sat})}\approx 0.2\ \text{V}. So Y≈0.2 VY\approx 0.2\ \text{V}, which the next gate reads as logic 00.

Step 2. Input LOW, A=0 VA=0\ \text{V}. Now the base–emitter junction is below its knee, no base current flows, and the transistor is in cutoff — an open switch. No collector current means no drop across the load resistor, so the output is pulled all the way up to the supply: Y=VCC=5 VY=V_{CC}=5\ \text{V}, which the next gate reads as logic 11.

Step 3. Tabulate the two rows. A=1⇒Y=0.2 V≈0A=1\Rightarrow Y=0.2\ \text{V}\approx 0; A=0⇒Y=5 V≈1A=0\Rightarrow Y=5\ \text{V}\approx 1. That is precisely the NOT truth table, Y=AˉY=\bar A. The 180∘180^\circ phase inversion that made the common-emitter stage an amplifier is, driven to the rails instead of kept in its linear region, exactly the logical inversion — same transistor, digital job.

Step 4. Notice what the two rail voltages buy you: an output of 0.2 V0.2\ \text{V} or 5 V5\ \text{V} is nowhere near the roughly 2.5 V2.5\ \text{V} mid-point, so a later gate can tell 00 from 11 even if noise adds a few tenths of a volt. This noise margin is why digital circuits are so robust — the very reason for banning the in-between voltages in the first place. Verified: saturation LOW ≈0.2 V\approx 0.2\ \text{V}, cutoff HIGH =5 V=5\ \text{V}, midpoint 2.5 V2.5\ \text{V}, and the NOT truth table (0→1, 1→0) — recomputed in verify_hs2-logic-gates.py.

NOR and NAND: two gates that do everything

Put an inverter on the output of an OR gate and you get NOR ("NOT-OR"): Y=A+B‾Y=\overline{A+B}. Put one on the output of an AND gate and you get NAND ("NOT-AND"): Y=A⋅B‾Y=\overline{A\cdot B}. On the symbols this inversion is drawn as a small bubble at the output, so a NOR is the OR shield with a bubble and a NAND is the AND D-shape with a bubble. Their truth tables are just the OR and AND tables with every output flipped.

ABNOR = A + B (bar)NAND = A · B (bar)
0011
0101
1001
1100

NOR outputs 11 only when both inputs are 00; NAND outputs 00 only when both inputs are 11. These inverted gates are tied to the basic ones by De Morgan's theorems, the two most useful identities in all of Boolean algebra. The first says the complement of an OR is the AND of the complements:

A+B‾  =  Aˉ⋅Bˉ(2)\overline{A+B} \;=\; \bar A\cdot\bar B \qquad (2)

where: the bar is logical NOT, ++ is OR and ⋅\cdot is AND. The physical reading: "not (A or B)" means "neither A nor B," i.e. both must be false — which is exactly the word "nor." The second theorem is its mirror image, the complement of an AND being the OR of the complements:

A⋅B‾  =  Aˉ+Bˉ(3)\overline{A\cdot B} \;=\; \bar A+\bar B \qquad (3)

Read aloud: "not (A and B)" means "A is false or B is false." De Morgan lets you push a bar through a bracket by flipping the operation and inverting each term — the single algebraic move that most exam simplifications turn on. You can prove both theorems in one breath by building the truth tables of the two sides and checking they match row for row, which we do in the verification script. Now the punchline of the whole chapter. NAND and NOR are universal gates: with copies of just one of them — nothing else — you can build NOT, AND and OR, and therefore every logic circuit that exists. This is not a mere convenience; it is why a real silicon chip is manufactured as a vast, uniform field of one gate type. One mask, one transistor pattern repeated millions of times, wired into whatever function is wanted.

Go deeper · Derivation B · 1 minNAND alone builds NOT, AND and OR — so NAND is universal
Derivation BNAND alone builds NOT, AND and OR — so NAND is universal

The goal is to prove that the single gate NAND is functionally complete: from NAND gates alone we can construct NOT, then AND, then OR, and since those three can express any Boolean function, so can NAND by itself. We need only the NAND rule NAND(A,B)=A⋅B‾\text{NAND}(A,B)=\overline{A\cdot B}, the idempotent law A⋅A=AA\cdot A=A, and De Morgan's theorem (3). Every construction is checked by its full truth table in the verification script.

Step 1. NOT from one NAND. Tie both NAND inputs together to the same signal AA. Then NAND(A,A)=A⋅A‾=Aˉ\text{NAND}(A,A)=\overline{A\cdot A}=\bar A, using A⋅A=AA\cdot A=A. One NAND gate with its inputs shorted is an inverter. Check: A=1⇒1⋅1‾=1ˉ=0A=1\Rightarrow\overline{1\cdot1}=\bar1=0; A=0⇒0⋅0‾=0ˉ=1A=0\Rightarrow\overline{0\cdot0}=\bar0=1 — the NOT table.

Step 2. AND from two NANDs. A NAND is an AND already inverted, so invert it again. Feed AA and BB to a first NAND to get A⋅B‾\overline{A\cdot B}, then pass that through a Step-1 inverter (a second NAND with inputs tied): A⋅B‾‾=A⋅B\overline{\overline{A\cdot B}}=A\cdot B. Two NAND gates make an AND.

Step 3. OR from three NANDs. By De Morgan (3), A+B=Aˉ⋅Bˉ‾=NAND(Aˉ,Bˉ)A+B=\overline{\bar A\cdot\bar B}=\text{NAND}(\bar A,\bar B). So invert each input with a NAND (Step 1), then NAND the two results: NAND(Aˉ,Bˉ)=Aˉ⋅Bˉ‾=A+B\text{NAND}(\bar A,\bar B)=\overline{\bar A\cdot\bar B}=A+B. Three NAND gates make an OR. (Counting: NOT needs 11, AND needs 22, OR needs 33.)

Step 4. Since {\{OR, AND, NOT}\} is functionally complete and each is now built from NAND alone, NAND by itself can express any logic function — it is universal. The identical argument with NOR (using NOR(A,A)=Aˉ\text{NOR}(A,A)=\bar A and the other De Morgan law) proves NOR is universal too. As a worked capstone, the "exactly one input high" gate XOR, Y=ABˉ+AˉBY=A\bar B+\bar A B, can be built from just four NAND gates — the standard construction real chips use. Verified: NAND-built NOT, AND, OR reproduce the basic truth tables exactly; the four-NAND XOR matches A⊕BA\oplus B; both De Morgan laws hold row-for-row — recomputed in verify_hs2-logic-gates.py.

Boolean algebra: the rules of the game

Boolean algebra is the arithmetic of true and false, and a handful of its laws let you shrink a tangle of gates into a clean expression before you draw a circuit. The variables are 00 and 11; the operations are ++ (OR), ⋅\cdot (AND) and the bar (NOT). Many rules look like ordinary algebra, but a few are startling because there are only two values. The basic identities every exam expects:

lawOR formAND form
with 00 / 11A+0=AA+0=AA⋅1=AA\cdot 1=A
annihilatorA+1=1A+1=1A⋅0=0A\cdot 0=0
idempotentA+A=AA+A=AA⋅A=AA\cdot A=A
complementA+Aˉ=1A+\bar A=1A⋅Aˉ=0A\cdot\bar A=0
double negation—Aˉˉ=A\bar{\bar A}=A

The two that have no arithmetic analogue are A+A=AA+A=A (an OR of a signal with itself is just the signal) and A+1=1A+1=1 (OR-ing anything with a constant true is always true). Add the distributive law A⋅(B+C)=A⋅B+A⋅CA\cdot(B+C)=A\cdot B+A\cdot C, the absorption law A+A⋅B=AA+A\cdot B=A, and the identity A+Aˉ⋅B=A+BA+\bar A\cdot B=A+B, and you have enough to simplify almost every school circuit. For instance Y=A⋅B+A⋅BˉY=A\cdot B+A\cdot\bar B factors to A⋅(B+Bˉ)=A⋅1=AA\cdot(B+\bar B)=A\cdot 1=A: two gates and an inverter collapse to a plain wire. De Morgan's theorems (2) and (3) complete the toolkit, letting you trade NANDs and NORs for AND/OR/NOT and back. The goal is always the same — fewest gates, cheapest chip.

Limiting cases

caseresultmeaning
OR with one input held at 11Y=A+1=1Y=A+1=1output stuck HIGH — a 11 input forces OR true
OR with one input held at 00Y=A+0=AY=A+0=Athe gate passes the other input unchanged
AND with one input held at 00Y=A⋅0=0Y=A\cdot 0=0output stuck LOW — a 00 input forces AND false
AND with one input held at 11Y=A⋅1=AY=A\cdot 1=Athe gate passes the other input unchanged
NAND with inputs tiedY=A⋅A‾=AˉY=\overline{A\cdot A}=\bar Athe universal gate becomes a NOT
NOR with inputs tiedY=A+A‾=AˉY=\overline{A+A}=\bar Athe other universal gate becomes a NOT
nn inputs2n2^{n} truth-table rowscomplexity doubles per added input

Worked examples

Board level — output of a two-gate combination (CBSE and ICSE pattern)

In the circuit, inputs A and B go to a NAND gate; its output and input B go to a second NAND gate, whose output is Y. Build the truth table for Y and name the single gate it is equivalent to.

Step 1. First NAND: P=A⋅B‾P=\overline{A\cdot B}. Tabulate PP for the four input rows: (0,0)→1(0,0)\to1, (0,1)→1(0,1)\to1, (1,0)→1(1,0)\to1, (1,1)→0(1,1)\to0.

Step 2. Second NAND takes PP and BB: Y=P⋅B‾Y=\overline{P\cdot B}. Row by row: (P,B)=(1,0)→1(P,B)=(1,0)\to1; (1,1)→0(1,1)\to0; (1,0)→1(1,0)\to1; (0,1)→1(0,1)\to1.

Step 3. Collect YY against the original A,BA,B: (0,0)→1(0,0)\to1, (0,1)→0(0,1)\to0, (1,0)→1(1,0)\to1, (1,1)→1(1,1)\to1.

Step 4. Compare with the named gates. YY is 00 only in the row A=0,B=1A=0,B=1; it is 11 everywhere else. That is the rule Y=A+BˉY=A+\bar B — HIGH unless B alone is HIGH. So the two-NAND network is equivalent to an OR of A with NOT-B. The lesson: chase the signal gate by gate, writing the intermediate column, and only compare to named gates at the end.

Board level — simplify a Boolean expression and count the gates saved (CBSE and JEE pattern)

Simplify Y=A⋅B+A⋅Bˉ+Aˉ⋅BY=A\cdot B+A\cdot\bar B+\bar A\cdot B using Boolean algebra, and state how many gates the simplified form needs.

Step 1. Group the first two terms and factor AA: A⋅B+A⋅Bˉ=A⋅(B+Bˉ)A\cdot B+A\cdot\bar B=A\cdot(B+\bar B). By the complement law B+Bˉ=1B+\bar B=1, so this is A⋅1=AA\cdot 1=A.

Step 2. The expression is now Y=A+Aˉ⋅BY=A+\bar A\cdot B. Apply the identity A+Aˉ⋅B=A+BA+\bar A\cdot B=A+B (or expand: A+AˉB=(A+Aˉ)(A+B)=1⋅(A+B)=A+BA+\bar A B=(A+\bar A)(A+B)=1\cdot(A+B)=A+B).

Step 3. So Y=A+BY=A+B — a single OR gate. The unsimplified form needed two inverters, three AND gates and one OR (six gates); the simplified form needs one. Confirm by truth table: the original is 11 for every row except A=0,B=0A=0,B=0, which is exactly the OR table. The moral for exams: always simplify before drawing — marks (and, in industry, silicon) are won by the shorter expression.

Competitive level — build a half adder and read off its two gates (JEE Main and Advanced pattern)

A half adder adds two single bits A and B and produces a sum bit S and a carry bit C, so that the two-bit binary number C SC\,S equals A+BA+B in ordinary arithmetic. Work out the truth table for S and C, and identify which gate produces each.

Step 1. Do the binary arithmetic for all four input pairs. 0+0=00+0=0 (so C=0,S=0C=0,S=0); 0+1=10+1=1 (C=0,S=1C=0,S=1); 1+0=11+0=1 (C=0,S=1C=0,S=1); 1+1=1021+1=10_2, i.e. two (C=1,S=0C=1,S=0).

Step 2. Read the S column against A,BA,B: S=0,1,1,0S=0,1,1,0. That is 11 when the inputs differ — the XOR rule, S=A⊕B=ABˉ+AˉBS=A\oplus B=A\bar B+\bar A B.

Step 3. Read the C column: C=0,0,0,1C=0,0,0,1, which is 11 only when both inputs are 11 — the AND rule, C=A⋅BC=A\cdot B.

Step 4. So a half adder is just one XOR gate for the sum and one AND gate for the carry. Sanity check the encoding: in the 1+11+1 row, C S=102=2C\,S=10_2=2, matching 1+1=21+1=2 — the carry is the "tens" (here "twos") digit, the sum is the "units." This tiny circuit, chained with a carry-in, becomes the full adder that does all the arithmetic in a processor. Timing note: under a minute. The whole item is one line of binary addition per row; the instant you see S=0110S=0110 down the column, write "XOR," and C=0001C=0001 is "AND" on sight. Do not derive XOR from scratch — recognise the "outputs 1 when inputs differ" pattern and name it.

Competitive level — count the NAND gates for a target function (JEE Advanced pattern)

Using only 2-input NAND gates, how many are needed to build (a) an inverter, (b) an AND gate, (c) an OR gate, and (d) an XOR gate? Assume inputs and their use as many times as needed.

Step 1. Inverter: tie both inputs of one NAND together, NAND(A,A)=Aˉ\text{NAND}(A,A)=\bar A. One gate.

Step 2. AND: a NAND followed by an inverting NAND, A⋅B‾‾=A⋅B\overline{\overline{A\cdot B}}=A\cdot B. That is 11 (the NAND) + 1+\,1 (the inverter) == two gates.

Step 3. OR: by De Morgan, A+B=Aˉ⋅Bˉ‾A+B=\overline{\bar A\cdot\bar B} — invert each input (two NANDs) then NAND them (one more). Three gates.

Step 4. XOR: the standard construction is Y= A⋅AB‾‾⋅B⋅AB‾‾ ‾Y=\overline{\,\overline{A\cdot\overline{AB}}\cdot\overline{B\cdot\overline{AB}}\,}, which lays out as one NAND for AB‾\overline{AB}, two NANDs combining it with A and with B, and a final NAND — four gates. So the tally is 1,2,3,41,2,3,4. The exam point: the more a target gate differs from NAND's own AND-then-invert shape, the more NANDs it costs, and XOR — needing a "differ" test — is the priciest of the common gates. Timing note: about ninety seconds if you have the four counts memorised as 11–22–33–44 for NOT–AND–OR–XOR. Deriving the four-NAND XOR live under exam pressure is a time sink; recall the count, and if a circuit is given, just verify one or two rows rather than the whole table.

Exam traps

Writing 1+1=21+1=2 in a Boolean line. The ++ is OR, so 1+1=11+1=1. Every stray "22" (or a carry that should not exist) in a truth table costs the row. Keep arithmetic addition and logical OR in separate mental boxes; the half-adder question above is the one place binary addition is intended, and even there the carry is handled by a gate, not by the OR symbol.

Confusing OR with XOR on the 1,11,1 row. Plain OR is inclusive: 1+1=11+1=1. The gate that gives 00 for two 11s is XOR, a different gate. If a truth table has 00 in the both-inputs-high row and 11 in the two mixed rows, it is XOR, not OR.

Forgetting the bubble means invert. A NAND is not an AND, and a NOR is not an OR; the output bubble flips every output. Students who copy the AND table for a NAND lose the whole question. Bubble on the symbol, bar on the expression, flip in the table — all three say the same thing.

Mangling De Morgan. Pushing a bar across a bracket must flip the operation and invert every term: A+B‾=Aˉ⋅Bˉ\overline{A+B}=\bar A\cdot\bar B, not Aˉ+Bˉ\bar A+\bar B. Writing A+B‾=Aˉ+Bˉ\overline{A+B}=\bar A+\bar B is the single most common Boolean error on JEE and A-Level papers.

Naming the wrong universal gates. NAND and NOR are the universal ones; AND, OR and NOT individually are not (you cannot build a NOT from AND gates alone, for example). And "universal" means "can build any circuit," not "used most often" — though in practice they are that too.

Board scope. Logic gates, their symbols and truth tables, NAND/NOR as universal gates, and basic Boolean simplification are core on CBSE (Ch. 14), ICSE (ISC), JEE Main, JEE Advanced, and NEET. IGCSE 0625 carries the qualitative gate story — the symbols and truth tables of AND, OR, NOT, NAND, NOR (and often XOR) — but not Boolean-algebra simplification or the universal-gate proofs; an IGCSE answer completes truth tables, it does not manipulate expressions. Note: semiconductor electronics, and therefore logic gates, is not on AP Physics 2, and IB Physics has moved electronics out of its core — do not cite either board for this topic.

Origins · 1 minClaude Shannon and how this was discovered
CS
Claude Shannon
1916–2001 · Petoskey Michigan and MIT and Bell Labs

Claude Elwood Shannon was the American mathematician and engineer who married logic to circuits. As a 2121-year-old master's student at MIT, his 1937 thesis A Symbolic Analysis of Relay and Switching Circuits proved that the two-valued algebra George Boole had written a century earlier describes networks of on/off switches exactly — series switches are AND, parallel switches are OR, a normally-closed contact is NOT. It has been called the most important master's thesis of the century, because it is the theoretical bedrock of every digital computer: it says circuits can be designed and simplified by algebra. Later, at Bell Labs, his 1948 A Mathematical Theory of Communication founded information theory and introduced the term bit — a word he explicitly credited to J. W. Tukey. Every gate in this article is Shannon's thesis made of silicon.

History
1847
— George Boole recasts logic as an algebra of just two values in "The Mathematical Analysis of Logic."
1854
— Boole's "An Investigation of the Laws of Thought" completes the system now called Boolean algebra.
1913
— Henry Sheffer shows a single operation (the "Sheffer stroke", now usually written as NAND) can generate all of logic.
1937
— Claude Shannon's MIT master's thesis shows relay switching circuits obey Boolean algebra — logic becomes electrical.
1947
— Bardeen and Brattain build the first (point-contact) transistor at Bell Labs (Shockley's junction transistor follows in 1948) — the switch every modern gate is made from.
1966
— Texas Instruments' 7400-series TTL puts NAND gates on a chip and Boolean logic goes mass-market.

Going further

Texts. NCERT Physics Class 12, Chapter 14 ("Semiconductor Electronics"), the logic-gates section · H. C. Verma, Concepts of Physics Vol. 2, "Semiconductors and Devices" · Morris Mano, Digital Design, for Boolean algebra and gate minimisation done properly · Floyd, Digital Fundamentals, for the diode/transistor gate circuits.

Provenance. All logic values are exact (Boolean), verified by full truth tables. Recompute: truth tables of OR, AND, NOT, NAND, NOR and XOR; row count N=2nN=2^{n} (22=42^{2}=4, 23=82^{3}=8); number of distinct 2-input functions 222=162^{2^{2}}=16; both De Morgan laws over all four input rows; NAND-built NOT/AND/OR reproducing the basic tables; four-NAND XOR matching A⊕BA\oplus B; NOR universality; Boolean simplifications AB+ABˉ=AA B+A\bar B=A and AB+ABˉ+AˉB=A+BAB+A\bar B+\bar A B=A+B; half-adder S=A⊕BS=A\oplus B, C=A⋅BC=A\cdot B with 2C+S=A+B2C+S=A+B; gate counts NOT/AND/OR/XOR =1/2/3/4=1/2/3/4 from NAND; and the circuit voltages VCC=5 VV_{CC}=5\ \text{V}, VCE(sat)=0.2 VV_{CE(\text{sat})}=0.2\ \text{V}, diode drop 0.7 V0.7\ \text{V}, diode-OR HIGH =5−0.7=4.3 V=5-0.7=4.3\ \text{V}, diode-AND LOW =0.7 V=0.7\ \text{V}, midpoint 2.5 V2.5\ \text{V} — all in verify_hs2-logic-gates.py.

Prerequisites. The Junction Diode & its I–V Curve supplies the one-way valve that steers current in the diode OR and AND gates, and The Bipolar Junction Transistor supplies the saturation/cutoff switch that makes the NOT gate — this article assumes both. Leads to. Semiconductor & Logic Numericals, the chapter's archetype problem set, where these truth tables are worked alongside band-gap, mass-action, rectifier and current-gain sums. For the university seam, digital-design courses take Boolean minimisation (Karnaugh maps, Quine–McCluskey) and sequential logic (flip-flops, state machines) far beyond this page — enrichment only, never an exam dependency here.

What is the difference between a logic gate and an ordinary switch?

An ordinary switch is opened or closed by hand; a logic gate is a small circuit whose output is set automatically by the voltages on its input wires, following a fixed rule. Feed a gate its inputs and it decides the output for you — HIGH or LOW — in a few billionths of a second, with no moving parts. The link between the two is Shannon's insight: a gate behaves as if it were a tiny arrangement of switches (series for AND, parallel for OR), but those "switches" are diodes and transistors thrown by the input voltages themselves. So a gate is best thought of as an automatic switch network that computes a truth value rather than one you flip.

Why do we only use two voltage levels — isn't that wasteful?

It looks wasteful, but two levels is what makes digital electronics reliable. If a wire is allowed only near 0 V0\ \text{V} or near 5 V5\ \text{V}, then a stray few tenths of a volt of noise cannot be mistaken for a different value — the receiving gate simply rounds back to the nearer rail. This noise margin lets a signal pass through thousands of gates without degrading, something an analogue "in-between" voltage could never do, because small errors would accumulate. Two states also map perfectly onto true/false, onto Boolean algebra, and onto the binary numbers a computer counts in. The price — needing many wires to represent big numbers — is tiny compared with the robustness gained.

What makes NAND and NOR "universal" and the basic gates not?

Universal means you can build every possible logic function using copies of that one gate alone. NAND qualifies because from NAND you can make NOT (tie its inputs together), then AND (a NAND plus an inverter), then OR (De Morgan), and OR-AND-NOT can express anything. NOR works the same way. A single basic gate cannot do this: AND gates alone can never produce an inverter, because ANDing true inputs can only ever give true — you can never manufacture the "flip" that NOT needs. The magic ingredient NAND and NOR carry, which the plain basics lack, is a built-in inversion, and inversion is the one operation you cannot fake from non-inverting gates.

Why are real chips made mostly of NAND gates?

Two reasons, one logical and one physical. Logically, NAND is universal, so a designer never needs another gate type — one building block covers the whole design, simplifying the masks and the design tools. Physically, in the CMOS technology chips are built from, a NAND (and a NOR) comes out simpler and faster than the AND or OR it is based on, because AND and OR are literally made as NAND-then-invert — the inverting version is the natural one and the non-inverting one costs an extra stage. So the gate that is both universal and cheapest to fabricate wins, and that is NAND.

How is XOR different from OR, and why does it need more gates?

OR is inclusive: it outputs 11 if either input is 11 or both are. XOR ("exclusive OR") outputs 11 only if the inputs differ — exactly one is 11 — so it gives 00 when both are 11, the single row where it parts company with OR. That "not both" condition cannot be expressed as one simple AND or OR; it needs a combination, ABˉ+AˉBA\bar B+\bar A B, which is why XOR takes several basic gates (or four NANDs) rather than one. XOR earns its keep in arithmetic: it is exactly the sum bit of adding two bits (with AND giving the carry), so every adder in every processor is built around XOR gates.

Do I have to memorise all the truth tables, or can I work them out?

Work them out from the rule, then the tables are automatic and un-forgettable. OR: output 11 unless all inputs are 00. AND: output 00 unless all inputs are 11. NOT: flip. NAND and NOR: write the AND or OR table, then invert every output. For a multi-gate circuit, add a column per gate and fill it left to right. The only two you might simply memorise are XOR (output 11 when inputs differ) and its complement XNOR (output 11 when inputs agree), since they do not read off a one-word rule as cleanly. Beyond that, the rules are faster and safer than rote memory, especially when an exam invents an unfamiliar gate combination.

Is Boolean algebra the same algebra I use in maths class?

It shares the notation and some laws, but the variables take only two values, and that changes everything. Distribution, commutation and association work as you expect, but you also get laws with no ordinary analogue: A+A=AA+A=A, A+1=1A+1=1, A⋅A=AA\cdot A=A, and A+Aˉ=1A+\bar A=1. Crucially ++ is OR (so 1+1=11+1=1, never 22) and there is no subtraction or division — the bar (NOT) plays the role of "opposite." De Morgan's theorems, which let you push a bar through a bracket by flipping AND↔OR, have no counterpart in number algebra at all. Treat it as its own small system whose whole purpose is simplifying logic circuits, and the surprising identities stop feeling like mistakes.

Before this

Where this leads