Skip to main contentSkip to navigation
ThisIsHowItWorks.in

Complex systems, clearly explained.

An independent visual publication explaining the invisible protocols, networks, infrastructure, and mechanisms that run our world.

Explainers

  • How UPI Works
  • Offline UPI Mechanisms
  • All Explainers (Archive)
  • Topics & Roadmap
  • Curated Library

Publication

  • About Publication
  • Editorial Principles
  • Theme Index
  • Technical Lexicon
  • Open Questions
  • Changelog
  • RSS / Atom Feed

Legal & Contact

  • Privacy Policy
  • Terms of Use
  • Editorial & Legal Notice
  • Contact Us

Connect

  • Instagram
  • Discord Community
© 2026 ThisIsHowItWorks.in. All rights reserved.
Durable technical understanding built from first principles.
ThisIsHowItWorks.in
ExploreTopicsPathsAbout
  1. Home
  2. /Topics
  3. /Computing & Digital Architecture
  4. /Computing & Digital Architecture
  5. /How Binary Arithmetic Logic Units Actually Add Numbers
Computing · Computing/ Explainer

How Binary Arithmetic Logic Units Actually Add Numbers

From half adders and ripple-carry latency to carry-lookahead prefix trees, two's complement subtraction, and status flag generation in physical silicon

24 min read·Updated for clarity
The Short AnswerFirst-Principles Core

“How does an Arithmetic Logic Unit add two 64-bit binary numbers in a fraction of a nanosecond when carry bits must travel across 64 consecutive stages?”

Chaining 1-bit Full Adders into a Ripple-Carry Adder creates a severe bottleneck: the carry bit must crawl through 64 gate pairs before producing a sum. Modern Arithmetic Logic Units solve this with Carry-Lookahead Adders and parallel prefix trees (Kogge-Stone and Brent-Kung). By computing Generate and Propagate signals simultaneously across logarithmic tree levels, ALUs resolve 64-bit addition in a handful of gate delays.

What This Explainer Answers
  • How do XOR, AND, and OR gates combine to form a 1-bit Full Adder?
  • Why is a 64-bit Ripple-Carry Adder far too slow for modern gigahertz processors?
  • What are Generate (G) and Propagate (P) signals in a Carry-Lookahead Adder?
  • How do parallel prefix adders (Kogge-Stone) compute carries in O(log N) gate delays?
  • How does two's complement subtraction use the exact same adder circuit as addition?
  • How are CPU condition flags (Zero, Negative, Carry, Overflow) derived from electrical voltages?
  • How does an ALU multiplexer select which operation to output on the datapath?
Recommended Background
Relationship: Requires understanding of

To build a complete first-principles mental model of this mechanism, we recommend starting with these foundational explainers:

Requires understanding of
How Binary and Logic Gates Became Computation
Understanding How Binary and Logic Gates Became Computation is required before reading How Binary Arithmetic Logic Units Actually Add Numbers
Requires understanding of
How CMOS Transistors Form Logic Gates
Understanding How CMOS Transistors Form Logic Gates is required before reading How Binary Arithmetic Logic Units Actually Add Numbers
In this Explainer6 Sections
  1. 01The Speed of Light in Copper and the Ripple-Carry Wall
  2. 02The Breakthrough: Carry-Lookahead Logic
  3. 03Logarithmic Scaling: Parallel Prefix Trees (Kogge-Stone)
  4. 04Two's Complement: Subtraction with the Same Hardware
  5. 05The Generation of Condition Flags
  6. 06Datapath Multiplexing: The Complete Arithmetic Unit

The Speed of Light in Copper and the Ripple-Carry Wall

When a software engineer writes c = a + b, the central processing unit has less than a single clock tick—often less than 250 picoseconds (0.25 ns) in a 4 GHz chip—to accept two 64-bit binary numbers, compute their sum, generate arithmetic condition flags, and store the result into a register.

In elementary binary arithmetic, addition is performed column by column from right to left, exactly like pencil-and-paper decimal addition:

    Carries:   1 1 1 0 0 0
    Operand A: 0 0 1 1 1 0 1 1  (59)
  + Operand B: 0 0 0 1 0 1 1 1  (23)
  ─────────────────────────────
    Sum:       0 1 0 1 0 0 1 0  (82)

To implement this in silicon, digital designers build a circuit called a 1-bit Full Adder. A full adder accepts three 1-bit inputs—Operand Ai, Operand Bi, and an incoming carry bit Ci from the column to the right—and produces two outputs: the Sum bit Si and an outgoing Carry bit Ci+1.

The Boolean equations for a full adder are derived directly from binary truth tables:

Si = Ai ⊕ Bi ⊕ Ci
Ci+1 = (Ai · Bi) + (Ci · (Ai ⊕ Bi))
         Ai ────────┬────────────────┐
                    │                │
         Bi ─────┬──┼────────────┐   │
                 │  │            │   │
               ┌─┴──┴─┐        ┌─┴───┴┐
               │ XOR1 │        │ AND1 │
               └──┬───┘        └───┬──┘
                  │ (A ^ B)        │ (A & B)
         Ci ───┬──┼────────┐       │
               │  │        │       │
             ┌─┴──┴─┐    ┌─┴───┐   │
             │ XOR2 │    │AND2 │   │
             └──┬───┘    └──┬──┘   │
                │           │      │
             Sum (Si)       └──┬───┘
                               │
                             ┌─┴──┐
                             │ OR │
                             └─┬──┘
                               │
                           Carry Out (C_i+1)

In physical CMOS logic, the XOR gate and the AND-OR logic each introduce approximately two gate delays (roughly 15 to 25 picoseconds per stage in modern silicon).

If you connect 64 of these full adders in a linear chain—where the Cout of stage 0 feeds the Cin of stage 1, the Cout of stage 1 feeds stage 2, and so on—you construct a Ripple-Carry Adder (RCA).

 A0 B0 C0       A1 B1          A2 B2                  A63 B63
  │  │  │        │  │           │  │                    │  │
┌─▼──▼──▼─┐    ┌─▼──▼──┐      ┌─▼──▼──┐               ┌─▼──▼──┐
│ Full    │ C1 │ Full  │  C2  │ Full  │               │ Full  │ C64
│ Adder 0 ├────► Adder ├──────► Adder ├─── ... ───────► Adder ├────► Overflow
└────┬────┘    └─1──┬──┘      └──2─┬──┘               └──63┬──┘
     │              │              │                       │
     S0             S1             S2                     S63

Now consider what happens in the worst-case scenario: adding 1 to a number consisting of 63 consecutive ones (0111...111 + 0000...001).

The carry bit generated at bit position 0 must physically ripple through all 64 adders before bit 63 can calculate its sum bit S63. If each full adder takes 25 picoseconds to resolve its carry output, the total carry propagation delay is:

tdelay = 64 × 25 ps = 1,600 ps = 1.6 nanoseconds

An adder that takes 1.6 nanoseconds cannot operate faster than 625 MHz. At 4 GHz, the processor's clock cycle is only 250 ps. The ripple-carry adder is six times too slow for modern computing.


The Breakthrough: Carry-Lookahead Logic

In 1958, computer scientists realised that a circuit does not actually need to wait for a carry to ripple down the line to know whether one will be created or passed along.

By examining only the two input bits Ai and Bi at stage i, the circuit can immediately determine two fundamental properties before any carry arrives:

  1. Generate (Gi): If both Ai = 1 and Bi = 1, this bit position will guarantee the creation of a carry out, regardless of whether a carry came in from the right:
Gi = Ai · Bi
  1. Propagate (Pi): If either Ai = 1 or Bi = 1 (or in XOR form, exactly one is 1), any incoming carry from the right will be propagated through to the next stage:
Pi = Ai ⊕ Bi   (or Ai + Bi)

With Gi and Pi established, the carry-out equation simplifies into an elegant linear expression:

Ci+1 = Gi + Pi · Ci

"The carry out of stage i is 1 if stage i generated a carry, OR if stage i propagated an incoming carry."

Now comes the mathematical leap: recursive substitution. We can write every carry bit purely in terms of the initial carry-in C0 and the immediately available G and P signals:

For Stage 0:

C1 = G0 + P0 C0

For Stage 1:

C2 = G1 + P1 C1 = G1 + P1(G0 + P0 C0) = G1 + P1 G0 + P1 P0 C0

For Stage 2:

C3 = G2 + P2 C2 = G2 + P2 G1 + P2 P1 G0 + P2 P1 P0 C0

For Stage 3:

C4 = G3 + P3 G2 + P3 P2 G1 + P3 P2 P1 G0 + P3 P2 P1 P0 C0

Look closely at the equation for C4. It does not depend on C1, C2, or C3. It depends only on C0 and the input bits of the preceding stages.

In physical silicon, this means that C4 can be calculated using a two-level AND-OR circuit. The carry signal does not ripple through four sequential full adders; it is evaluated in exactly two gate delays, regardless of word length.

Carry-Lookahead Addition Execution Stages
01
P & G Generation

Evaluates G_i = A_i & B_i and P_i = A_i ^ B_i simultaneously across all 64 bits (1 gate delay)

→
02
Parallel Prefix Carry Tree

Kogge-Stone tree merges (G, P) terms across 6 logarithmic levels in ~100 picoseconds

→
03
Sum & Flag Computation

Calculates S_i = P_i ^ C_i in parallel and derives Zero, Negative, Carry, and Overflow flags

→
04
Bus Drive & Register Latch

Drives 64-bit result into register file on the rising clock edge

Pipeline diagram showing the four parallel stages of high-speed binary addition: Input operands enter Stage 1 to generate P and G signals; Stage 2 evaluates the logarithmic parallel prefix tree; Stage 3 computes the final sum bits and arithmetic status flags; Stage 4 drives the result onto the CPU destination register bus.

Logarithmic Scaling: Parallel Prefix Trees (Kogge-Stone)

While the carry-lookahead equation works brilliantly for 4 bits, a practical limitation arises when expanding to 64 bits: gate fan-in.

Look at the equation for C4: the final AND gate requires four inputs (P3 P2 P1 P0). For bit 64, an elementary carry-lookahead gate would require an AND gate with 65 physical inputs, and an OR gate with 65 physical inputs.

In physical CMOS, connecting 65 transistor gates in series would create a channel resistance so immense that the circuit would become slower than a ripple-carry adder. In standard cell libraries, the maximum allowable fan-in for a single gate is typically 4.

To solve this, modern microprocessors arrange the carry calculations into a Parallel Prefix Network. The most celebrated of these architectures is the Kogge-Stone Adder, invented by Peter Kogge and Harold Stone in 1973.

The Kogge-Stone adder relies on the mathematical fact that carry generation is an associative operator. We define a carry operator ∘ acting on pairs of (G, P) signals:

(G'', P'') ∘ (G', P') = (G'' + P'' · G',  P'' · P')

Because this operation is associative:

(A ∘ B) ∘ C = A ∘ (B ∘ C)

Carries can be combined in any grouping. Instead of a linear sequence of 64 steps (O(N)), the Kogge-Stone adder organizes the calculation into a binary tree of logarithmic depth:

Levels = log2(64) = 6 levels
Bit:      7       6       5       4       3       2       1       0
Input:   (G,P)   (G,P)   (G,P)   (G,P)   (G,P)   (G,P)   (G,P)   (G,P)  (Level 0)
           │       │       │       │       │       │       │       │
Step 1:    ├───┐   ├───┐   ├───┐   ├───┐   ├───┐   ├───┐   ├───┐   │    (Distance 1)
           ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   ▼   │
Step 2:    ├───────┼───┐   ├───────┼───┐   ├───────┼───┐   │   │   │    (Distance 2)
           ▼       ▼   ▼   ▼       ▼   ▼   ▼       ▼   ▼   ▼   ▼   │
Step 3:    ├───────────────┼───────┼───┐   │       │   │   │   │   │    (Distance 4)
           ▼               ▼       ▼   ▼   ▼       ▼   ▼   ▼   ▼   │
Carries:  C7      C6      C5      C4      C3      C2      C1      C0    (All Carries Ready)

In a Kogge-Stone adder:

  • At Step 1, each bit combines its (G, P) with its immediate neighbor (distance 1).
  • At Step 2, each node combines with the node 2 positions away.
  • At Step 3, each node combines with the node 4 positions away.
  • By Step 6, every single bit position from 0 to 63 has received the combined prefix of all preceding bits.

Total time to resolve all 64 carries: just 6 logic levels, completing in approximately 120 picoseconds. The addition completes well within the 250 ps clock budget of a 4 GHz CPU.


Two's Complement: Subtraction with the Same Hardware

In elementary mathematics, addition (+) and subtraction (−) are distinct operations requiring different algorithms. If a microprocessor required a separate set of 64-bit subtractor circuits alongside its adders, the arithmetic core would consume double the silicon area and double the electrical power.

Instead, computer hardware exploits a beautiful property of modular arithmetic: Two's Complement representation.

To subtract B from A:

A − B = A + (−B)

In binary, the negative of a two's complement number is obtained by inverting every bit (one's complement, ∼ B) and adding 1:

−B = ∼ B + 1

Therefore:

A − B = A + (∼ B) + 1

Look at that formula: subtraction is simply an addition where operand B is bit-inverted, and the carry-in to the lowest bit (C0) is set to 1.

             B63             B1              B0
              │               │               │
  SUB ────┬───┼───────────┬───┼───────────┬───┼──────── (SUB Control Line)
          │ ┌─┴─┐         │ ┌─┴─┐         │ ┌─┴─┐
          └─┤XOR│         └─┤XOR│         └─┤XOR│
            └─┬─┘           └─┬─┘           └─┬─┘
              │ B63'          │ B1'           │ B0'
              │   A63         │   A1          │   A0
              │    │          │    │          │    │
            ┌─▼────▼─┐      ┌─▼────▼─┐      ┌─▼────▼─┐
            │ Stage  │      │ Stage  │      │ Stage  │
            │   63   │◄─...─┤   1    │◄─────┤   0    │◄─── SUB (C0 = 1)
            └────────┘      └────────┘      └────────┘

Chip architects place an XOR gate on every bit line of Operand B. The second input of each XOR gate is tied to a single control wire called SUB:

  1. When performing Addition (SUB = 0):
    • Bi ⊕ 0 = Bi (Operand B passes through unchanged).
    • C0 = 0.
    • The circuit computes A + B + 0 = A + B.
  2. When performing Subtraction (SUB = 1):
    • Bi ⊕ 1 = ∼ Bi (Every bit of Operand B is cleanly inverted).
    • C0 = 1 (The carry-in is injected directly into stage 0).
    • The circuit computes A + (∼ B) + 1 = A − B.

A single wire transforms a 64-bit adder into a high-speed subtractor with zero additional adder hardware.


The Generation of Condition Flags

When an ALU executes an arithmetic operation, software frequently needs to branch based on the result:

  • if (x == y) (Branch if equal)
  • if (x < y) (Branch if less than)
  • if (overflow) (Handle numeric overflow)

A CPU does not perform a second calculation to test these conditions. During the exact picoseconds that the sum bits are settling, dedicated CMOS logic monitors the internal voltages of the ALU and asserts four standardized Condition Code Flags in the CPU's Status Register (often named EFLAGS or RFLAGS on x86, or CPSR on ARM):

┌───────────────────────────────────────────────────────────┐
│                      ALU Flags Register                   │
├─────────────┬─────────────┬───────────────┬───────────────┤
│   Zero (Z)  │  Sign (N)   │   Carry (C)   │  Overflow (V) │
└─────────────┴─────────────┴───────────────┴───────────────┘

1. The Zero Flag (Z)

  • Meaning: Asserted (1) if every single bit of the 64-bit result is 0.
  • Physical Circuit: A 64-input NOR tree. If any sum bit S0, S1, …, S63 is HIGH, the NOR output drops to 0. If and only if all 64 bits are LOW, the output floats to VDD (1).
  • Software Use: Powers equality checks (CMP A, B followed by JE / BEQ). If A − B = 0, the Z flag is set, confirming A = B.

2. The Negative/Sign Flag (N or S)

  • Meaning: Asserted (1) if the arithmetic result is negative in two's complement.
  • Physical Circuit: In two's complement representation, the most significant bit (MSB, bit 63) is the sign bit. The circuit requires zero logic gates: it is a direct copper trace tapping bit S63 straight into the flags register:
N = S63

3. The Carry Flag (C)

  • Meaning: Asserted (1) if an unsigned operation generated a carry out of the most significant bit, or if a borrow occurred during subtraction.
  • Physical Circuit: The carry out of the final prefix tree stage:
C = C64
  • Software Use: Enables multi-precision arithmetic. To add two 256-bit numbers on a 64-bit CPU, the processor executes four sequential ADC (Add with Carry) instructions, with each stage consuming the C flag left behind by the preceding 64-bit addition.

4. The Overflow Flag (V or O)

  • Meaning: Asserted (1) if a signed two's complement operation produced a result that exceeds the representable range (for 64-bit signed integers, −263 to +263−1).
  • Physical Phenomenon: Occurs when two positive numbers are added and produce a negative number, or when two negative numbers are added and produce a positive number.
  • Physical Circuit: An XOR gate comparing the carry entering the most significant bit with the carry leaving the most significant bit:
V = C63 ⊕ C64
  • If C63 ≠ C64, signed overflow has occurred.

Datapath Multiplexing: The Complete Arithmetic Unit

An ALU is not merely an adder; it must also perform logical operations: bitwise AND, OR, XOR, NOT, and bit-shifting.

In modern silicon, these operations are computed in parallel simultaneously. When operands A and B arrive from the register file, they are dispatched concurrently to:

  1. The 64-bit Parallel Prefix Adder/Subtractor
  2. A bank of 64 parallel AND gates
  3. A bank of 64 parallel OR gates
  4. A bank of 64 parallel XOR gates
  5. A barrel shifter circuit
                   Operand A [63:0]    Operand B [63:0]
                          │                   │
             ┌────────────┼───────────────────┼────────────┐
             │            │                   │            │
           ┌─▼────────────▼─┐               ┌─▼────────────▼─┐
           │ Prefix Adder / │               │  Bitwise Logic │
           │   Subtractor   │               │ (AND, OR, XOR) │
           └───────┬────────┘               └───────┬────────┘
                   │                                │
                   │  ┌─────────────────────────────┘
                   ▼  ▼
           ┌──────────────────┐
           │ Output 64-to-1   │◄─── ALU Opcode Control Lines
           │   Multiplexer    │     (from Instruction Decoder)
           └────────┬─────────┘
                    │
                    ▼
          ALU Result Bus [63:0] ──► Register Writeback

While the adder is evaluating its carry tree, the simple AND, OR, and XOR gates resolve their results in a single gate delay (15 ps).

The final output is selected by an output multiplexer controlled by opcode wires arriving from the CPU's Instruction Decoder. The decoder simply asserts the address of the desired operation, and the multiplexer passes the selected 64-bit result onto the CPU's internal datapath to be written back into a register on the rising edge of the clock.

Through this breathtaking choreography of Boolean algebra, modular arithmetic, and logarithmic tree routing, the ALU converts raw electric voltage into the unstoppable computational powerhouse of modern civilization.

Guided Learning Path · Step 4 of 8
View Full Path (8 Steps)

How Computers Execute and Store Information

Starting question: “How does purified quartz sand doped with boron and phosphorus become a microprocessor capable of executing billions of arithmetic instructions and running an operating system every second?”

Why This Step Matters in the Path

Combines XOR and AND gates into half-adders, full-adders, and carry-lookahead circuits that perform binary addition, subtraction, and comparisons in picoseconds.

Conceptual Progression
1.How Semiconductors and Transistors Actually Work→
2.How Binary and Logic Gates Became Computation→
3.How CMOS Transistors Form Logic Gates→
4.How Binary Arithmetic Logic Units Actually Add Numbers→
5.How a CPU Executes an Instruction→
6.How CPU Cache Hierarchies Overcome the Memory Wall→
7.How an Operating System Actually Runs Software→
8.How Compilers Translate Human Code into Machine Instructions
Previous Step (3/8)
How CMOS Transistors Form Logic Gates
Next Step (5/8)
How a CPU Executes an Instruction
Core Concepts Introduced8 Concepts
1-Bit Full Adder (Sum and Carry Logic)Ripple-Carry Adder (RCA) Propagation DelayCarry Generate (G) and Propagate (P) FunctionsCarry-Lookahead Adder (CLA) Recursive ExpansionParallel Prefix Trees (Kogge-Stone / Brent-Kung)Two's Complement Inversion & SubtractionArithmetic Status Flags (Z, N, C, V)ALU Function Select Multiplexing
Knowledge Graph Connections

Where to Go From Here

Follow downstream mechanisms, contrasting architectures, or applications of these principles.

Answers next question24 min read

How Compilers Translate Human Code into Machine Instructions

How does a compiler turn abstract lines of human-readable programming language into raw binary machine instructions that silicon microprocessors can execute?

Explore How Compilers Translate Human Code into Machine Instructions
Answers next question23 min read

How CPU Cache Hierarchies Overcome the Memory Wall

Why does a CPU core wait 200 clock cycles for main memory, and how do layered SRAM caches supply instructions and data in less than a nanosecond?

Explore How CPU Cache Hierarchies Overcome the Memory Wall
Answers next question25 min read

How Relational Databases Guarantee ACID Transactions Without Corrupting Data

How do relational database engines guarantee that multi-step transactions execute completely or leave zero trace, while hundreds of concurrent clients read and write the same tables and server power can vanish at any microsecond?

Explore How Relational Databases Guarantee ACID Transactions Without Corrupting Data
Answers next question25 min read

How Hardware Security Modules (HSM) Protect Cryptographic Keys

Why can't private encryption keys be safely kept in computer memory, and how do Hardware Security Modules physically self-destruct secrets when attacked?

Explore How Hardware Security Modules (HSM) Protect Cryptographic Keys
Research Grounding & Primary Sources

Verified Specifications & Architectural References

3 Authoritative References

This explainer is grounded in primary-source engineering specifications, regulatory circulars, and standard documentation.

Primary SourceIEEE Transactions on Computers (Peter M. Kogge, Harold S. Stone)• 1973

A Parallel Algorithm for the Efficient Solution of a General Class of Recurrence Equations

The seminal paper establishing parallel prefix recurrence algorithms and the Kogge-Stone adder topology for logarithmic-time addition.

Primary SourceIEEE Transactions on Computers (Richard P. Brent, H. T. Kung)• 1982

A Regular Layout for Parallel Adders

Introduces the Brent-Kung parallel prefix tree adder, optimizing silicon wiring density and fan-out constraints for VLSI hardware.

Primary SourcePrentice Hall (Amos R. Omondi)• 1994

Computer Arithmetic Systems: Algorithms, Architecture and Implementation

Comprehensive treatise on two's complement arithmetic, high-speed adders, carry-lookahead formulations, and ALU flag generation.

Previous ExplainerHow CMOS Transistors Form Logic GatesNext Explainer How the CPU Clock Synchronizes Billions of Transistors
More from Computing & Digital Architecture•Topic Hub: Computing & Digital Architecture
Ground Truth Engineering Publication