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

How to build an 8-bit adder, with carry and overflow flags

An 8-bit adder chains eight full adders, each passing its carry to the next, so it adds two bytes plus a carry-in and outputs an 8-bit sum and a carry-out. This live one also has the signed overflow flag V = c7 XOR c8, which is 1 when two's complement numbers add to a result outside -128 to 127.

Each full adder adds one bit position: A_i, B_i and the carry from the bit below. The same circuit adds unsigned numbers (0 to 255) and signed two's complement numbers (-128 to 127); only the reading of the result changes, and so does the flag that says it went wrong. For unsigned numbers that flag is the carry-out: 200 + 100 = 300 does not fit, Cout = 1 and S = 44. For signed numbers it is overflow, which happens when the carry into the sign bit differs from the carry out of it, so one XOR gate computes it: 100 + 50 = 150 fits as unsigned but is out of range as signed, so V = 1 and S reads as -106. A CPU's status register keeps both flags because the hardware cannot know which reading the program means; see carry vs overflow. Each full adder here is a saved part built from the full adder circuit; for the 4-bit version gate by gate, see the ripple-carry adder. Eight edge cases and 300 seeded random sums are checked, every sum bit, Cout and V, 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 A7 to A0, B7 to B0 and Cin, and probes S7 to S0, Cout and V.
  2. Place eight full adders in a row; wire A_i and B_i into adder i and its sum to S_i.
  3. Chain the carries: Cin into adder 0, each Cout into the next adder's Cin, and the last Cout to the Cout probe.
  4. Overflow: XOR the carry into adder 7 with the carry out of it and send it to V.
  5. Try 0111 1111 + 0000 0001 (127 + 1): S = 1000 0000, Cout = 0 and V = 1, because the signed answer 128 does not fit and reads as -128.

Carry and overflow examples

ABSUnsignedSignedCoutV
0110 01000011 00101001 0110100 + 50 = 150100 + 50 = -106 (overflow)01
1100 10000110 01000010 1100200 + 100 = 44 (wrapped)-56 + 100 = 4410
0111 11110000 00011000 0000127 + 1 = 128127 + 1 = -128 (overflow)01
1111 11110000 00010000 0000255 + 1 = 0 (wrapped)-1 + 1 = 010
1000 00001000 00000000 0000128 + 128 = 0 (wrapped)-128 + -128 = 0 (overflow)11
0100 00000010 00000110 000064 + 32 = 9664 + 32 = 9600

Carry and overflow are independent: 255 + 1 sets the carry but not overflow (-1 + 1 = 0 is fine as signed), 127 + 1 sets overflow but not the carry, and 128 + 128 sets both.

You can also read the full theory in the lesson on the 8-bit adder. 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 Kogge-Stone adder4-bit carry-skip adder4x4 Wallace tree multiplierfrequency 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 8-bit adder in the lab →

Frequently asked

How do you make an 8-bit adder?

Chain eight full adders: each adds A_i, B_i and the carry from the bit below, outputs the sum bit S_i, and passes its carry-out to the next adder. The first carry-in is Cin (0 for plain addition) and the last carry-out is Cout.

How many full adders are in an 8-bit adder?

Eight, one per bit. If the lowest bit never needs a carry-in, it can be a half adder, but keeping a full adder there lets Cin chain adders together or turn the adder into a subtractor.

What is the overflow flag in an 8-bit adder?

V = 1 when adding two's complement numbers gives a result outside -128 to 127. It equals the carry into bit 7 XOR the carry out of bit 7; equivalently, it is 1 when both inputs have the same sign and the sum has the other sign.

What is the difference between carry and overflow?

Carry-out reports that an unsigned result did not fit in 8 bits; overflow reports that a signed result did not fit. 255 + 1 carries without overflow, 127 + 1 overflows without a carry.

How do you make an 8-bit adder from two 4-bit adders?

Connect the carry-out of the low 4-bit adder (bits 0 to 3) to the carry-in of the high one (bits 4 to 7). That is exactly the same ripple chain as eight full adders in a row.