How an ALU Works: The Heart of CPU Architecture Explained
Don't just read about the ALU, learn how to build one. Let's break down the Arithmetic Logic Unit into 1-bit circuits using adders, multiplexers, and logic gates. Perfect for students of computer architecture.
In the previous chapter, we constructed circuits that could add numbers together, starting from a simple Half-Adder and progressing to an 8-bit Adder. That was our first glimpse into how arithmetic happens inside a computer. But adders are just the beginning. Computers need a dedicated component to perform not only arithmetic but also logical decisions. This is where the Arithmetic Logic Unit, or ALU, comes in.
Arithmetic… what?
As mentioned earlier, the 8-bit adder was our first look at how arithmetic works inside a computer. However, a computer needs to do much more than add two numbers. With some clever circuitry, we can extend our 8-bit adder to create an 8-bit Subtractor. If we fix the B input of both the adder and subtractor to 00000001, we effectively create an incrementer and a decrementer, respectively.
Inside the CPU, all these circuits live together inside a special component called the Arithmetic Logic Unit (ALU). Whenever your computer needs to perform arithmetic operations or make logical decisions, the ALU is the one doing the work. You can think of it as the calculator at the heart of the processor, but one that also understands logic.
At its core, an ALU is a circuit that takes inputs, performs an operation, and produces an output. The inputs usually come from CPU registers, and the operation performed depends on what the program instructs. The result is then sent back to a register or to memory for later use.
What makes the ALU powerful is its flexibility. The same hardware can perform many different tasks depending on the control signals it receives. Depending on the control signals it receives, the ALU might add two numbers one moment, compare them the next, or even shift bits left or right.
Modern ALUs are often divided into two main parts:
- Arithmetic Unit (AU): Handles mathematical operations such as addition, subtraction, multiplication, and division.
- Logic Unit (LU): Handles logical operations such as AND, OR, XOR, and NOT.
Some CPUs take this even further, including separate arithmetic units for different types of data. For example, one unit might handle fixed-point arithmetic (integers), while another handles floating-point arithmetic (real numbers used in scientific or graphics calculations).
Arithmetic
Let’s take a closer look at how the circuits inside the ALU perform arithmetic. We already know from the previous chapter how an 8-bit adder works, and how to build incrementers and decrementers from it. But we haven’t yet seen how a subtractor works. Let’s start there.
Just like before, we begin small, with the Half-Subtractor. The Half-Subtractor is similar to the Half-Adder: it has two inputs and two outputs. However, unlike the Half-Adder, it includes a NOT gate before the AND gate.
The first output, referred to as the Difference, represents the result of subtracting B from A. The second output, the Borrow, indicates that when the digit being subtracted (B) is larger than the digit it’s subtracted from (A), we need to “borrow” from the next higher bit, just like in decimal subtraction.
Here’s how that looks conceptually:

The truth table for a Half-Subtractor is as follows:
| A | B | Difference | Borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 1 | 0 | 0 |
To create the Full-Subtractor, we combine two Half-Subtractors. It has three inputs: A, B, and B-in (the borrow from a previous stage).
- A and B connect to the first Half-Subtractor.
- Its Difference output connects to the A input of the second Half-Subtractor, while B-in connects to its B input.
- The two Borrow outputs are combined through an OR gate to produce a single Borrow out (B-out).
Connecting eight of these Full-Subtractors forms an 8-bit Subtractor, which can handle multi-bit binary subtraction, just like the adder, but with borrowing instead of carrying.

Logic
Arithmetic is only half the story; the other half is logic. The Logic Unit performs operations like AND, OR, XOR, and NOT directly on the binary bits of its inputs. Why does this matter? Because logic operations allow a computer to make decisions. For example, the ALU can compare two numbers to determine whether they are equal, greater, or less than. This information is critical for loops, conditional statements, and control flow in programs. Without logic operations, a computer could calculate, but it couldn’t decide.
Control Signals
Now that we understand what the ALU does and how it works, one question remains: how does it know what operation to perform? The ALU doesn’t choose its operation on its own. Instead, it listens to instructions sent by the Control Unit in the form of binary codes known as opcodes (operation codes). Depending on the opcode, the ALU may perform addition, subtraction, comparison, or logical operations.
Here’s an example of how different control signals might map to ALU operations:
| Opcode (Control Signal) | Operation |
|---|---|
| 000 | ADD |
| 001 | SUBTRACT |
| 010 | AND |
| 011 | OR |
| 100 | XOR |
| 101 | NOT |
Inside the ALU, a multiplexer (MUX) acts as a selector. You can think of a multiplexer as an electronic switch that selects one of many inputs and forwards it to a single output, based on control signals. Each operation (add, subtract, AND, and so on) is implemented as a separate circuit. All of them receive the same inputs and produce their results in parallel, but only one of these outputs is actually sent to the final result line. The MUX, controlled by the opcode, chooses which one.
This approach might seem inefficient at first; after all, why compute everything if you only need one result? But it makes the ALU incredibly fast. Since all operations are ready at once, the MUX can instantly select the required output without waiting for a circuit to “turn on.”
Building a Simple 1-bit ALU
Now that we know how arithmetic and logic operations work, and how control signals tell the ALU what to do, let’s put everything together and build a simple 1-bit ALU.
A 1-bit ALU performs one operation on one pair of input bits (A and B) at a time. When we combine multiple 1-bit ALUs (usually eight, sixteen, or thirty-two of them), we get a multi-bit ALU capable of handling entire binary numbers. But just like before, we’ll start small.
The Idea
Our ALU will have:
- Two inputs: A and B
- One control signal: to decide what operation to perform
- One output: the result of that operation
For simplicity, let’s say our ALU only performs the following operations:
| Opcode | Operation | Description |
|---|---|---|
| 00 | AND | Logical AND between A and B |
| 01 | OR | Logical OR between A and B |
| 10 | XOR | Logical XOR between A and B |
| 11 | ADD | Adds A and B (with carry out) |
In circuit form, we’ll have four separate mini-circuits, one for each operation. The outputs from all four will feed into a multiplexer (MUX). The MUX then selects which output to send to the final result, based on the control signal.

How it works step-by-step
- Inputs arrive: Two bits, A and B, are fed into the ALU.
- Each mini-circuit does its job:
- The AND gate outputs
A AND B. - The OR gate outputs
A OR B. - The XOR gate outputs
A XOR B. - The adder calculates
A + B.
- The AND gate outputs
- Opcode is set: The CPU sends a 2-bit control signal telling the ALU which operation to use.
- MUX selects output: The multiplexer chooses the correct result and passes it to the output line.
Here’s an example of how it behaves:
| A | B | Control | Operation | Result |
|---|---|---|---|---|
| 0 | 1 | 00 | AND | 0 |
| 0 | 1 | 01 | OR | 1 |
| 1 | 1 | 10 | XOR | 0 |
| 0 | 1 | 11 | ADD | 1 |
Summary
- The ALU is the part of the CPU that performs both arithmetic and logic operations.
- It consists of an Arithmetic Unit (AU) and a Logic Unit (LU).
- Control signals from the control unit tell the ALU which operation to perform.
- A multiplexer (MUX) selects the correct operation result.
In the next chapter, we’ll meet the Control Unit, the “brain” of the CPU that tells the ALU and every other component exactly what to do and when to do it.