Skip to main content
Be Bitwise

AND, OR, and NOT

Logic Gates · Foundations track

3 min read

In this module

What Are Logic Gates?

Last module, you learned that computers work in bits, zeros and ones. So how does a computer actually do things with those bits? The answer: logic gates. A logic gate is a tiny circuit that takes one or more binary inputs and produces a single binary output according to a specific rule.

Every calculation your computer performs, from adding numbers to rendering graphics, ultimately boils down to millions of logic gates firing in concert. Start with the three most fundamental ones.

The AND Gate

An AND gate outputs 1 only when both of its inputs are 1. If either input is 0, the output is 0.

ABA AND B
000
010
100
111

Picture two switches wired in series. The light comes on only when both are closed.

The OR Gate

An OR gate outputs 1 when at least one of its inputs is 1. The output is 0 only when both inputs are 0.

ABA OR B
000
011
101
111

Same two switches, but this time wired in parallel. Close either one and the light comes on.

The NOT Gate

The NOT gate is the runt of the litter, and the simplest gate of all. One input, and it flips it: 0 becomes 1, 1 becomes 0. The operation is called inversion.

ANOT A
01
10
Key Concept

AND, OR, and NOT are the three fundamental logic gates. Every digital circuit ever built can be constructed from combinations of these three operations. The tables that define their behaviour are called truth tables, and they are the primary tool for understanding any gate.

Try the Gates

Add an AND, an OR and a NOT gate to the canvas below, then click the input boxes to flip them between 0 and 1. The table underneath shows each gate's current inputs and output, so you can walk through every row of the truth tables above and check that the gates agree.

Add gate:
Select a gate type and click "+ Add" to begin

Combining Gates

Single gates get interesting once you feed one gate's output into another. Take a burglar alarm with a rule like this: the alarm sounds if the door is open and the system is armed, or if someone presses the panic button. That's two gates, an AND feeding an OR:

Evaluate it one gate at a time, starting from the inputs:

doorarmedpanicdoor AND armedalarm
10000
11011
00101

The first row is you coming home with the alarm off: door open, nothing happens. The third is the panic button doing its job whatever state the door is in. Every circuit you meet later, up to a full CPU, gets evaluated this same way, layer by layer.

From Switches to Silicon

These gates aren't just abstract ideas. Inside a real processor, they're built from transistors, tiny electronic switches etched into silicon. A transistor is either on or off, which maps perfectly onto 1 and 0. Arrange transistors in specific patterns and you have physical circuits that implement AND, OR, and NOT behaviour.

Next lesson, we'll meet three more gates built on these fundamentals.