Skip to 0 minutes and 0 secondsIn this step, we're going to have a look at how transistors can be combined together to form what are called logic gates. And in particular, we'll look at the NAND gate. We've already seen how transistors can be used to store the value 1 or 0 by acting like a simple switch. We're now going to look at combining those transistors together so they can perform more complex operations. Here, we have a circuit set up containing two transistors. Again, you don't have to understand what is going on in this circuit, just as long as you can understand the basic inputs and outputs. The two switches are acting as inputs to the transistor setup, and the LED represents the output.

Skip to 0 minutes and 39 secondsAt the moment, when both inputs are in the off position, the LED is on. Either of the inputs can be turned on, leaving the other one off, and the LED will stay on. It's only when both inputs are turned on that the LED will switch off. This arrangement of transistors is called a NAND gate, and you'll learn about why later. Now, rather than drawing two transistors every time we want to represent a NAND gate, we can use a symbol that looks like this. Whether we're using the symbol or the two transistors, the inputs and outputs remain the same. When both inputs are off, the output is on. Turning either of the inputs on doesn't affect the output.

Skip to 1 minute and 22 secondsAnd only when both inputs are in the on position does the output become off.

Skip to 1 minute and 29 secondsWe can use this to draw what is called a truth table. With both inputs at 0 and 0, the lamp is on, so the output is 1. If either of the becomes 1, the lamp remains on, so the output remains 1. Only when both inputs are 1 does the output change to 0. So this is the truth table for a NAND gate. You can play with your own simulation of a NAND gate on the website circuitverse.org. Here you can select different gates. You can select inputs, which can be a 1 or a 0, and outputs in the form of a digital LED.

Skip to 2 minutes and 11 secondsThis will allow you to play around with a NAND gate and have a look at the truth table for yourself. You could even have a go to experimenting with different types of gates, which we'll be covering in the next step.

Creating NAND gates

In this step, we’re going to have a look at how transistors can be combined together to form what are called logic gates, and in particular we’ll look at the NAND gate.

We’ve already seen how transistors can be used to represent the value 1 or 0 by acting like simple switches. We’re now going to look at combining these transistors together so they can perform more complex operations.

The diagram below shows a circuit containing two transistors. Again you don’t have to understand what is going on in this circuit, just as long as you can understand the basic inputs and outputs.

A circuit where two switches each control the current going to the base of a transistor. The transistors are connected in series with each other, and in parallel with an LED.

The two switches are acting as inputs to the transistor setup, and the LED represents the output. When both switches are in the off position, the LED is on. Either of the switches can be turned on, leaving the other one off, and the LED still stays on. It’s only when both switches are turned on that the LED will switch off.

An animation showing the circuit from the previous image, with the LED remaining on apart from when both switches are switched to "on".

This arrangement of transistors is called a NAND gate, and you’ll learn about why later.

Now, rather than drawing two transistors every time we want to represent a NAND gate, we can use a symbol that looks like this.

A symbol that looks like an extended D with a small circle touching its right-most point. Two input and an output are represented with larger circles connected with a straight line - the inputs are connected on the left-hand side approximately one quarter and three quarters of the way down the straight edge of the D, and the output is connected on the right-hand side to the small circle.

Whether we use this symbol or show the two transistors, the behaviour of the NAND gate is the same. When both switches are off, the output is on. Turning either of the switches individually doesn’t effect the output. Only when both switches are in the “on” position does the output become “off”.

An animation showing two switches connected to the inputs of a NAND gate symbol, with the output connected to a bulb. The bulb remains on apart from when both switches are switched on, at which point the bulb is off.

We can represent this behaviour by drawing what is called a truth table, where the state of the switches is represented by 1s and 0s. When both switches are off, the inputs are both 0. Since the lamp is on, the output in this state is 1. If we turn one of the switches to the “on” position, the corresponding input is 1; the lamp remains on, so the output is 1. Only when both inputs are one does the output change to 0.

An animation showing the truth table for the NAND gate being constructed. The switches, gate and bulb from the previous animation are on the left. On the right is a table with 3 columns, labelled "Input A", "Input B" and "Output". As the states of the switches and hence the bulb are changed, this table updates with values.

So the full truth table for a NAND gate is as shown below.

A table with three columns, labelled "Input A", "Input B" and "Output". The first row reads 0 0 1, the second 1 0 1. The third row reads 0 1 1 and the final row 1 1 0.

You can play with your own simulation of a NAND gate on the website CircuitVerse.

A screenshot of circuitverse.org, showing a NAND gate attached to two digital inputs and a digital LED. The inputs are both at 1 and the LED is off

Here you can select different gates, and choose inputs which can be 1 or 0, with outputs in the form of a digital LED. This will allow you to play around with a NAND gate and investigate the truth table for yourself.

You could even have a go at experimenting with different types of gate, which we will be covering in the next step.

Share this video:

This video is from the free online course:

How Computers Work: Demystifying Computation

Raspberry Pi Foundation