Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

How a Kogge-Stone adder works: a 4-bit parallel prefix adder

A Kogge-Stone adder computes every carry in parallel with a prefix tree: each bit makes a generate signal g = A AND B and a propagate signal p = A XOR B, and log2(n) levels of small cells combine them so that carry i is ready after only log2(n) cell delays. This live 4-bit one needs two prefix levels.

The cells all do one job. A gray cell takes a high group (Gh, Ph) and the group just below it (Gl) and outputs G = Gh OR (Ph AND Gl): the combined group generates a carry if its upper part does, or if the upper part propagates one that the lower part generates. A black cell also outputs P = Ph AND Pl, for use one level later. Level 1 joins neighbours (span 1), level 2 joins groups two apart (span 2), so with n bits the carries are done after log2(n) levels; Cin enters at bit 0 as G0 = g0 OR (p0 AND Cin). Peter Kogge and Harold Stone described the scheme in 1973. It is the fastest of the classic prefix adders because every cell drives at most two others, at the price of many cells and long wires; the carry-lookahead adder computes the same carries with wide flattened gates instead, and the ripple-carry adder waits for them one bit at a time. All 512 combinations of A, B and Cin are checked against real addition before the page is built.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place inputs A3 to A0, B3 to B0 and Cin, and probes S3 to S0 and Cout.
  2. For each bit make p = A XOR B and g = A AND B.
  3. Fold Cin into bit 0: G0 = g0 + p0 Cin. This is carry c1.
  4. Level 1 (span 1): G1:0 = g1 + p1 G0 (carry c2), G2:1 = g2 + p2 g1, G3:2 = g3 + p3 g2, with P2:1 = p2 p1 and P3:2 = p3 p2.
  5. Level 2 (span 2): G2:0 = G2:1 + P2:1 G0 (carry c3) and G3:0 = G3:2 + P3:2 G1:0 (Cout). Then S_i = p_i XOR c_i, with c0 = Cin.

Worked examples

ABCingpCarries c4 c3 c2 c1SCout
00110001000010010001101000
01010010000000111000001110
01110001000010110011110000
10001000110000000100000011
11110000100001111111100001

In the last row nothing generates but every bit propagates, so the carry-in runs all the way out: the prefix tree finds that in two levels, where a ripple-carry adder needs four full-adder delays. The circuit has 26 gates, against 20 for a 4-bit ripple-carry adder; at 64 bits the difference in delay is 6 levels against 64 stages.

You can also read the full theory in the lesson on faster adders and carry lookahead. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

Build more parts from gates

half adderfull adderhalf subtractorfull subtractor2:1 multiplexer4:1 multiplexerXOR gate from NAND gates2-to-4 decoderSR latchD flip-flopJK flip-flopT flip-flop4-bit shift register4-bit ripple carry adderD latch1-to-4 demultiplexer4-bit magnitude comparator4-bit ring counter4-bit Johnson counter4-to-2 priority encoder4-bit synchronous counter3-to-8 decoder8-to-1 multiplexer4-bit carry lookahead adderhalf adder from NAND gates2-bit comparatorBCD to 7-segment decoder4-bit up/down counterdecade counter2-bit multiplier4-bit ALU4-bit array multiplierNOT, AND, OR and NOR from NANDNOT, OR, AND and XOR from NORfull adder from NAND gatesSR latch from NAND gatesparity generator and checker4-bit adder/subtractorBCD adder4-bit universal shift registermod-6 counter4-bit ripple counterbinary to Gray code converterhalf adder from NOR gatesfull adder from NOR gates4-bit register with parallel load1011 sequence detectorbinary to BCD converterD flip-flop from NAND gates1-bit ALUCMOS inverterCMOS NAND gateCMOS NOR gatePISO shift registerSR flip-flop from NAND gatesBCD to excess-3 code converterHamming (7,4) code encoder and correctortraffic light controller4-bit barrel shifterCMOS AND gateCMOS OR gateCMOS XOR gate1-bit magnitude comparatorhalf subtractor from NAND gatesfull subtractor from NAND gates8-to-3 encoderGray to binary converter4-to-16 decoderfull adder using 4:1 multiplexersedge detectorserial adder4-bit carry-select adder4-bit carry-skip adder4x4 Wallace tree multiplier8-bit adderfrequency divider (by 2, 4 and 3)switch debouncer (SR latch)3-bit Gray code counterMealy machine (1011 detector)master-slave JK flip-flop (NAND)half subtractor from NOR gates1-to-8 demultiplexerexcess-3 to BCD code convertervending machine FSM4-bit carry-save adder3-bit synchronous counter (JK)CMOS transmission gatetri-state buffer (CMOS)2-to-1 mux from transmission gatesmod-5 counterflip-flop conversion (JK to D)8-bit ALUdecimal to BCD encoderBCD to decimal decoder4-to-1 mux from 2-to-1 muxesXOR gate from NOR gates4-bit LFSR74LS138 decoderBCD subtractor

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the 4-bit Kogge-Stone adder in the lab →

Frequently asked

What is a Kogge-Stone adder?

A parallel prefix adder: every bit computes generate (A AND B) and propagate (A XOR B), and a tree of log2(n) levels of prefix cells combines them so that all carries are available at the same time. Each sum bit is then propagate XOR carry.

Why is the Kogge-Stone adder fast?

Its depth is log2(n) cell levels and every cell drives at most two others, so no carry waits for the bits below it one at a time. A 64-bit Kogge-Stone adder has 6 prefix levels where a ripple-carry adder has 64 full-adder stages.

What are black and gray cells?

A black cell combines two groups into both a group generate G = Gh + Ph Gl and a group propagate P = Ph Pl. A gray cell outputs only G, because nothing later needs that group's P. In this 4-bit adder there are 4 gray cells and 2 black cells.

What is the difference between Kogge-Stone and carry lookahead?

Both compute carries from generate and propagate signals. Classic carry lookahead expands each carry into one wide AND-OR expression per bit, which grows quickly with width; Kogge-Stone builds the same carries from small two-input cells in a tree of log2(n) levels, which scales to 32 or 64 bits.

What is the drawback of the Kogge-Stone adder?

Area and wiring: it uses about n log2(n) prefix cells and long wires that cross the whole width, so it costs more chip area and power than sparser prefix adders such as Brent-Kung, which trade a few more levels for far fewer cells.