Please enable JavaScript to use CodeHS

Circuits · How computers work

What Is a Transistor? How tiny switches power every computer

Your phone has billions of switches inside it, and none of them has a button. Each one is a transistor: a switch that electricity flips on and off. Learn how a transistor works, then switch one on yourself, build logic gates from them, and zoom from a phone all the way down to a single transistor.

Physical computing ~25 min 3 interactive labs
CORE 0 CORE 1 I/O CACHE MEMORY CTRL

Fig. 00 · A chip die, about the size of a fingernail

01 / The big idea

What is a transistor?

A transistor is a tiny switch that is turned on and off by electricity instead of by your finger. A small signal on one leg decides whether a bigger flow of electricity can pass between the other two legs. That one simple trick is what lets phones, laptops, game consoles, and AI chips think.

You already know how a light switch works. When you flip it on, metal parts touch, and electricity flows to the bulb. When you flip it off, the parts separate, and the flow stops. A transistor does the same job, but nothing moves. There are no metal parts that touch. Instead, a voltage on one leg changes the material inside so it lets electricity through, or blocks it.

Here is a helpful picture. Think of a garden hose with a valve in the middle. The water in the hose is like electric current, which is the flow of electric charge through a wire. The valve handle is the control. Turn the handle a little, and the water is blocked. Turn it past a certain point, and water rushes through. In a transistor, the "handle" is a voltage. Voltage is the push that makes charge want to move, like water pressure.

control handle water in water out

A water valve

Your hand turns a small handle. The handle controls a much bigger flow of water.

small control signal current in current out

A transistor

A small voltage on the control leg decides whether a bigger current can flow through.

Transistors are made from silicon, the same element found in sand. Pure silicon does not carry electricity well. Engineers add tiny amounts of other elements to it, a process called doping. That turns silicon into a semiconductor: a material that can act like a conductor (lets electricity through) or an insulator (blocks it), depending on the conditions. A transistor uses that "sometimes" behavior as its switch.

Why it matters: a switch has two states, off and on. Computers use those two states to stand for 0 and 1, the digits of binary. Every photo, song, game, and message on your phone is stored and processed as patterns of transistors that are off or on.

02 / Anatomy

The three legs: gate, drain, and source

Most transistors have three connections, often called legs or terminals. The kind used in almost every computer chip today is the MOSFET. The name is a mouthful (metal-oxide-semiconductor field-effect transistor), so everyone just says "MOSFET." Its three legs are:

ControlGateThe handle. A voltage here decides if the switch is on or off. The gate is separated from the silicon by a super-thin insulating layer, so almost no current flows into it.
InDrainOne end of the path. In a simple circuit it connects toward the power supply, often through the thing you want to control, like an LED.
OutSourceThe other end of the path. In a simple circuit it connects to ground, the "zero volts" side of the battery.
silicon (the base material) SOURCE DRAIN GATE insulator channel
A MOSFET, sliced open. When the gate voltage is high enough, a thin channel (teal) forms in the silicon and connects the source to the drain.

Here is the clever part. When you put a positive voltage on the gate, it pulls negative charges in the silicon up toward it, a little like a magnet pulling paper clips. Once enough charges gather right under the gate, they form a thin bridge called the channel. Now current can cross from drain to source. Take the voltage away, and the charges drift off. The bridge disappears, and the switch is off again.

The gate voltage has to reach a certain level before the channel forms. That level is the threshold voltage. Below it, the transistor is basically off. Above it, the transistor turns on. You will see this threshold in the lab below.

What about the other kind?

You may also see a BJT (bipolar junction transistor) in electronics kits. Its legs have different names, but the idea is similar.

 MOSFETBJT
Control legGateBase
Main pathDrain and sourceCollector and emitter
Controlled byA voltage on the gateA small current into the base
Where you find itAlmost every modern computer chipOlder circuits, audio gear, hobby kits

For the rest of this tutorial, we will focus on the MOSFET "gate" idea, because that is what fills the chips in your phone and computer.

03 / Lab 1

Transistor switch lab

Below is a simple circuit: a battery, an LED, a resistor, and one MOSFET. The resistor limits the current so the LED does not burn out (you can learn why in Ohm's Law and Simple Circuits). Slide the gate voltage up from 0 volts. Watch the channel, the LED, and the moving dots of current.

Interactive · Gate voltage

Open the channel, light the LED

Drag the slider or use the arrow keys. Find the voltage where the LED first starts to glow.

Circuit with a battery, LED, resistor, and a MOSFET shown sliced open. The LED and the channel under the gate light up when the gate voltage passes the threshold. + 5 V battery LED resistor S D G MOSFET (sliced open) 0.0 V gate ground

Simplified model: threshold 1.5 V, LED current capped at 20 mA by the resistor. Dots show conventional current (from + to ground). Real electrons drift the other way.

Current0 mA
LEDOff
OffThe gate voltage is below the threshold. No channel, no current.
threshold 0 2.5 5 V 20 0 mA

Did you notice three zones? Below the threshold, nothing happens. Just above it, the LED glows dimly, and small changes in gate voltage make big changes in brightness. Higher still, the LED hits full brightness and stays there. That top zone is where the transistor acts like a closed switch.

04 / Two jobs

Switch mode vs. amplifier mode

Those zones give a transistor two very different jobs.

0 1 0 1

Switch mode

The gate is either fully low or fully high. The transistor is either all the way off or all the way on, like a light switch. This is how transistors work in computer chips, where off means 0 and on means 1. Staying in the two extremes keeps the signal clean and easy to read.

small signal in big copy out

Amplifier mode

The gate sits in the middle zone, where a tiny wiggle in gate voltage makes a big wiggle in current. A weak signal, like the one from a microphone, controls a stronger current from the power supply. The result is a bigger copy of the signal, strong enough to drive a speaker.

No free energy: an amplifier does not create energy. The extra power comes from the battery or wall outlet. The small signal only controls how much of that power gets through, just like your hand on the valve does not supply the water.

The very first transistors were mostly used as amplifiers, in radios and hearing aids. Today, the number of transistors working as switches inside computer chips is far larger. That is the job we will explore next.

05 / Lab 2

From transistors to logic gates

One switch cannot do much. But wire a few together, and they start to make decisions. A logic gate is a small circuit that takes one or more inputs (each 0 or 1) and produces an output based on a rule. Three of the most important gates are:

  • NOT: flips the input. 0 becomes 1, and 1 becomes 0.
  • AND: outputs 1 only when input A and input B are both 1.
  • OR: outputs 1 when input A or input B (or both) is 1.

In the lab, each transistor is a switch whose gate is wired to an input. Input 1 means the gate gets a high voltage, so the transistor turns on. The LED is the output: lit means 1. Toggle the inputs, try every combination, and fill in the truth table, a chart that lists every possible input and the output it gives.

Interactive · Logic gate builder

Wire switches into decisions

+5 V T1 A OUT ground (0 V)
Output: 1

Inside real chips: these circuits use a resistor or an LED to keep things easy to see. Real chips use a design called CMOS, which pairs two kinds of transistors so that almost no current flows except at the moment a gate switches. That saves a huge amount of power. The logic rules are exactly the same.

From gates to a whole computer

Once you have gates, you can stack ideas on top of each other. Each layer is built from the one below it:

  1. TransistorsSwitches that are off (0) or on (1).
  2. Logic gatesA few transistors each. NOT, AND, OR, and friends.
  3. Adders and memoryGates that add binary numbers, plus loops of gates that "remember" a bit.
  4. ProcessorMillions of adders, memory cells, and control circuits working together.
  5. Your appsGames, browsers, and AI models, all running as billions of switch flips per second.

For example, a half adder adds two single bits. It uses one gate to make the "sum" bit and an AND gate to make the "carry" bit (because 1 + 1 = 10 in binary). Chain enough adders together, and you can add numbers of any size. A memory cell works differently: two gates feed their outputs back into each other, so the pair can hold a 0 or a 1 for as long as the power stays on.

AI chips, including the graphics processors that train and run AI models, are built from the same parts. They just use enormous numbers of transistors to do huge piles of simple math at the same time.

06 / History

From vacuum tubes to billions of transistors

Before transistors, electronic switches were vacuum tubes: glass bulbs, about the size of a thumb or bigger, that controlled current flowing through empty space inside them. They worked, but they were large, got hot, used lots of power, and burned out like light bulbs. ENIAC, an early general-purpose electronic computer finished in 1945, used about 18,000 vacuum tubes and filled a large room.

  1. 1947
    The first transistor. At Bell Labs in New Jersey, John Bardeen and Walter Brattain built a "point-contact" transistor from a chunk of germanium, gold foil, and a plastic wedge. William Shockley soon designed an improved version. The three later shared the 1956 Nobel Prize in Physics.
  2. 1950s
    Transistors replace tubes. Small, cool-running transistors showed up in hearing aids and pocket radios, then in computers. Engineers switched from germanium to silicon.
  3. 1958–59
    The integrated circuit. Jack Kilby at Texas Instruments and Robert Noyce at Fairchild Semiconductor each found ways to build several transistors and their wires on one piece of material. This was the first "chip."
  4. 1965
    Moore's observation. Gordon Moore noticed that the number of transistors on a chip was doubling at a steady pace. In 1975 he updated the pace to about every two years.
  5. 1971
    A processor on one chip. The Intel 4004, one of the first microprocessors, had about 2,300 transistors.
  6. Today
    Billions on a fingernail. Many phone and laptop processors have more than ten billion transistors. The biggest AI chips have tens of billions, and some chip packages pass one hundred billion.

Moore's law is an observation, not a law of nature

Moore's law is the name people gave to Gordon Moore's prediction that the number of transistors on a chip would keep doubling about every two years. It is not like the law of gravity. Nothing in physics forces it to happen. It held for decades because thousands of engineers worked hard to shrink transistors and pack them tighter. Now transistors are so small that some parts are only a few dozen atoms across, and the doubling has slowed. Engineers keep finding new tricks, such as stacking parts in 3D and building chips from several smaller pieces.

Watch out for names like "3 nm": chipmakers label their manufacturing steps with names like "5 nanometer" or "3 nanometer." These are mostly product names now. No single part of the transistor is actually exactly that size.

07 / Lab 3

Zoom from a phone to a single transistor

How small is "small"? Step down five zoom levels, from a phone in your hand to one transistor inside it. Each step shrinks things by a lot. The sizes are rough, because every chip is different.

Interactive · Scale explorer

Five levels down

Zoom illustration. The picture changes with each zoom level: a phone, its processor chip, one processor core, one logic gate, and one transistor. main chip CPUCPUCPUCPU GRAPHICSCACHEAI ENGINEI/O ADDERSFETCH / DECODEREGISTERSCONTROL POWER GROUND ABOUT SOURCE DRAIN GATE dots = silicon atoms (not to scale)
Level 1 of 5

Phone

About 15 cm tall

10 cm 1 cm 1 mm 0.1 mm 1 µm 100 nm 10 nm

A human hair is roughly a tenth of a millimeter wide. You could line up thousands of modern transistors across the width of one hair. Making them takes a wafer, a thin, shiny disk of pure silicon, and machines that print patterns using light, layer by layer, in super-clean factories. One wafer holds many chips, which are cut apart later.

08 / Build it

Using transistors in your own projects

You will likely use a transistor the first time you try to run a motor or a strip of LEDs from a microcontroller like an Arduino or micro:bit. Here is why.

A microcontroller pin can only give a small amount of current. On an Arduino Uno, each pin should stay at about 20 milliamps (mA) or less. A milliamp is one-thousandth of an amp. That is enough for one small LED. A small hobby motor can need hundreds of milliamps, and even more for a moment when it starts. A long LED strip can need an amp or more. If you connect those straight to a pin, the pin cannot keep up, and you can damage the board.

The fix is the same idea from the switch lab. The pin connects to the transistor's gate. The motor gets its power from a separate battery, through the transistor's drain and source. The pin only has to supply a tiny control signal, and the transistor handles the big current.

micro- controller PIN 9 GND MOSFET G D S M motor diode + − battery shared ground
A transistor lets a weak microcontroller pin switch a motor that runs on its own battery.
  1. Pick a "logic-level" MOSFET. Its threshold is low enough that a 3.3 V or 5 V pin can turn it fully on. Check the part's datasheet.
  2. Connect the grounds together. The battery's negative side and the microcontroller's ground must be linked, or the gate voltage has nothing to compare against.
  3. Add a diode across the motor. When a motor shuts off, it can kick back a quick voltage spike. A diode gives that spike a safe path so it does not harm the transistor.
  4. Use small resistors on the gate. A small resistor between the pin and gate is common, and a larger one from gate to ground keeps the transistor off while the board starts up.
  5. Prototype first. Build it on a breadboard so you can fix mistakes without soldering.

Once it is wired, the code is the easy part. The transistor follows the pin. Turning the pin on and off very quickly, called PWM (pulse-width modulation), even lets you control the motor's speed or an LED strip's brightness.

motor_speed.ino
const int MOTOR_PIN = 9;   // wired to the MOSFET gate

void setup() {
  pinMode(MOTOR_PIN, OUTPUT);
}

void loop() {
  analogWrite(MOTOR_PIN, 255);  // transistor fully on: full speed
  delay(2000);
  analogWrite(MOTOR_PIN, 100);  // on about 40% of the time: slower
  delay(2000);
  analogWrite(MOTOR_PIN, 0);    // transistor off: motor stops
  delay(2000);
}

Safety first: stick to low-voltage batteries for hobby projects, and never connect anything to a wall outlet. Ask an adult or teacher to check your wiring before you power up a motor.

09 / Vocabulary

Key terms

Transistor
A tiny switch or amplifier controlled by electricity. A small signal on one leg controls a bigger current between the other two.
Semiconductor
A material, like silicon, that can conduct electricity or block it depending on conditions.
MOSFET
The type of transistor in almost all computer chips. Its legs are the gate, drain, and source.
Gate
The control leg of a MOSFET. Its voltage decides whether the transistor is on or off.
Drain and source
The two ends of the path that current flows through when a MOSFET is on.
Channel
The thin path of charge that forms under the gate and connects the source to the drain.
Threshold voltage
The gate voltage needed before the channel forms and the transistor starts to turn on.
Amplifier
A circuit that uses a small signal to control a bigger one, making a stronger copy.
Logic gate
A small circuit of transistors that follows a rule like NOT, AND, or OR.
Truth table
A chart listing every possible input to a gate and the output it gives.
Integrated circuit (chip)
Many transistors and their connections built together on one small piece of silicon.
Moore's law
The observation that transistor counts on chips doubled about every two years for decades. It is a trend, not a law of nature.
10 / FAQ

Frequently asked questions

What is a transistor in simple words?

A transistor is a tiny switch that is turned on and off by electricity instead of by a finger. A small signal on one leg controls whether a bigger current can flow between the other two legs. Computer chips use billions of transistors as on and off switches to store and process ones and zeros.

How does a transistor work?

In the kind of transistor used in computer chips, called a MOSFET, there are three parts: the source, the drain, and the gate. When the voltage on the gate rises above a level called the threshold, it pulls a thin channel of charge into the silicon between the source and drain. Current can then flow through the channel. When the gate voltage drops, the channel disappears and the current stops.

How does a transistor work as a switch?

As a switch, a transistor is used only fully off or fully on. A low gate voltage keeps it off, so no current flows. A high gate voltage turns it fully on, so current flows freely. Off and on can stand for 0 and 1, which is how computers represent binary data.

How many transistors are in a computer chip?

It depends on the chip. The first single-chip microprocessor, the Intel 4004 from 1971, had about 2,300 transistors. Many modern phone and laptop processors have billions, often more than ten billion, and the largest AI chips have tens of billions or more.

What is the difference between a transistor and a logic gate?

A transistor is a single electrically controlled switch. A logic gate is a small circuit built from a few transistors that follows a rule, such as NOT, AND, or OR. Gates are combined into adders, memory, and eventually whole processors.

Is Moore's law a real law?

No. Moore's law is an observation, not a law of nature. In 1965 Gordon Moore noticed that the number of transistors on a chip was doubling at a steady pace, and in 1975 he revised the pace to about every two years. Engineers kept that trend going for decades through hard work, but it has been slowing down.

Why do I need a transistor to run a motor from an Arduino?

A microcontroller pin can only supply a small current, around 20 milliamps on an Arduino Uno. Motors and LED strips often need hundreds of milliamps or more. A transistor lets the weak pin signal switch a much bigger current that comes straight from a battery or power supply.


11 / Check yourself

Quick quiz

1. What does the gate of a MOSFET do?

2. In the switch lab, the gate voltage is 1.0 V and the threshold is 1.5 V. What happens?

3. Two transistors are wired in a line (in series) between power and an LED. When does the LED light?

4. Which statement about Moore's law is true?

5. Why do you need a transistor to run a motor from a microcontroller?

Keep learning

You just met the switch that every computer is built on. Next, see how those 0s and 1s turn into numbers and text, wire up real circuits, and program the chips that control them. In CodeHS courses, you can go from transistors and binary all the way to coding, cybersecurity, and AI.