1.1.5How Computers Work

Logic gates — physical gate symbols, transistor implementation idea

2,120 words10 min readdifficulty · medium6 backlinks

1. What is a logic gate?

WHAT are 0 and 1 physically?

  • 0 = LOW voltage (near 0 V0\text{ V}, "ground").
  • 1 = HIGH voltage (near the supply VddV_{dd}, e.g. 3.3 V3.3\text{ V}).

We don't measure exact voltages — we use thresholds (below some level = 0, above some level = 1). This is why digital logic is robust to noise: a little wobble in voltage still reads as the same bit.


2. The transistor: the underlying switch

Two flavours used together (this pairing is called CMOS):

Type Conducts (closes) when gate is Good at passing
NMOS HIGH (1) a strong 0 (pulls output down)
PMOS LOW (0) a strong 1 (pulls output up)

3. Building gates from transistors (derive, don't memorize)

3.1 The inverter (NOT gate) — first principles

Goal: output should be the opposite of the input.

Reason it out:

  • If input A=1A=1 (HIGH): we want output =0=0. So we need a path from output to ground. The NMOS conducts when its gate is HIGH → connect NMOS so input drives its gate. ✔ It pulls output to 0.
  • If input A=0A=0 (LOW): we want output =1=1. We need a path from output to VddV_{dd}. The PMOS conducts when its gate is LOW → same input AA on its gate pulls output to 1. ✔

So: one PMOS to VddV_{dd}, one NMOS to ground, both gates tied to AA. That's a complete CMOS NOT gate with just 2 transistors.

3.2 NAND from transistors

Rule we want: output is 0 only when both inputs are 1.

  • Pull-down (to ground) makes output 0 → needs both NMOS conducting → put two NMOS in series. Series = "AND" of conditions: both must be HIGH.
  • Pull-up (to VddV_{dd}) makes output 1 → needs either PMOS conducting → put two PMOS in parallel: if any input is LOW, output is pulled to 1.

Check: both inputs 1 → series NMOS conduct → out 0; parallel PMOS both off. Any input 0 → out 1. That is exactly NAND.


4. Gate symbols (the visual shorthand)

You must recognize these on sight. The small bubble (○) on an output always means "invert".

Figure — Logic gates — physical gate symbols, transistor implementation idea

Truth tables (the source of truth)

A B AND OR NAND NOR XOR XNOR
0 0 0 0 1 1 0 1
0 1 0 1 1 0 1 0
1 0 0 1 1 0 1 0
1 1 1 1 0 0 0 0

5. Worked examples


6. Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine light switches wired in clever ways. A NOT is a switch that turns the light OFF when you flip it ON. An AND light only glows if you press both buttons. An OR light glows if you press any button. Inside a real chip these "buttons" are tiny electric switches called transistors — too small to see, with no moving parts; a little voltage tells each one to let electricity through or block it. Wire a few together and the chip can suddenly add numbers — that's the whole magic of computers: nothing but switches saying yes/no super fast.


Flashcards

What physically is a logical 1 vs 0?
1 = HIGH voltage (near VddV_{dd}), 0 = LOW voltage (near ground); read via thresholds.
What are a MOSFET's three terminals?
Gate (control), source, drain.
When does an NMOS conduct?
When its gate is HIGH (1); it pulls the output toward ground (good at passing 0).
When does a PMOS conduct?
When its gate is LOW (0); it pulls the output toward VddV_{dd} (good at passing 1).
What does CMOS stand for / why used?
Complementary MOS: paired PMOS pull-up + NMOS pull-down; exactly one conducts → low power, strong output.
How many transistors in a CMOS inverter?
Two (one PMOS to VddV_{dd}, one NMOS to ground, gates tied to input).
In the pull-down network, series transistors implement which operation?
AND (all must conduct).
In the pull-down network, parallel transistors implement which operation?
OR (any one conducts).
What does a bubble (○) on a gate output mean?
Invert the output (NOT).
Why is NAND called universal?
Any Boolean function can be built using only NAND gates.
Build a NOT from one NAND.
Tie both NAND inputs to the same signal: AA=A\overline{A\cdot A}=\overline{A}.
Truth table difference between OR and XOR?
They agree except at A=B=1A=B=1: OR=1, XOR=0. XOR = "exactly one".
Boolean expression for XOR?
AB=ABˉ+AˉBA\oplus B = A\bar B + \bar A B.
What is AB\overline{A\cdot B} called?
NAND.

Connections

Concept Map

paired as

pull-down network

pull-up network

builds

implements

maps 0 or 1

LOW=0 HIGH=1

via thresholds

simplest gate

uses 2 transistors

stacked to

Transistor MOSFET switch

CMOS pair

NMOS conducts on HIGH

PMOS conducts on LOW

Logic gate

Boolean function

Single output bit

Voltage levels

Bit value

Noise robustness

Inverter NOT gate

Adders comparators memory

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, computer ke andar koi jaadu nahi hai — bas crore-crore chhote switch hain jinhe transistor kehte hain. Har transistor ke 3 point hote hain: gate, source, drain. Gate par voltage HIGH ya LOW karo, aur switch on/off ho jata hai — koi moving part nahi, sirf electric field ka khel. 1 matlab HIGH voltage, 0 matlab LOW voltage. Threshold se padhte hain, isliye thoda noise aaye to bhi bit galat nahi padhta.

In switches ko clever tarike se jodke logic gate banate hain. Sabse simple NOT gate: ek PMOS upar Vdd se, ek NMOS neeche ground se, dono ke gate par same input A. Jab A=0, PMOS conduct karta hai aur output 1 ho jata hai; jab A=1, NMOS conduct karta hai aur output 0. Bas 2 transistor mein input ka ulta mil gaya! Is PMOS-upar + NMOS-neeche jodi ko CMOS kehte hain, aur yahi har chip mein use hota hai kyunki power kam khaata hai.

Series mein transistor lagao to AND (sab on hone chahiye), parallel mein lagao to OR (koi bhi on ho jaye). Isi logic se NAND, NOR, XOR sab banate hain. Symbol yaad rakho: AND flat peeche, OR curved, aur bubble (○) ka matlab hamesha "ulta karo" (invert). Ek mast baat: sirf NAND se hi tum saari gates bana sakte ho — isliye usse "universal gate" kehte hain.

Kyun important hai? Kyunki tumhara C++/Python code last mein inhi gates par chalta hai. Numbers add karna, compare karna, memory mein store karna — sab in switches ke yes/no se hota hai, bas bahut tezi se. Gate samajh gaye, to computer ki neev samajh gaye.

Test yourself — How Computers Work

Connections