Bits and numbers · Adding one

What happens
after 255?

A byte can hold an unsigned number from 0 to 255. Start at 254 and add one twice. Where does the next number go?

First time here? Explore bits and numbers
Addition controls

Last addition · full mathematical sum

No addition yet.

256—Carry bit
Rightmost eight bits──── ────Stored in the byte

Enable JavaScript to add one. The byte starts at 254.

One byte · eight bitsUnsigned · 0 to 255

Enable JavaScript to change this byte. This example shows 254.

Change the byte

Hex digit F

Hex digit E

Add the values of the bits that are on

128 + 64 + 32 + 16 + 8 + 4 + 2 = 254

Edit the byte to choose a new starting point. Each addition uses the current byte; the carry shown belongs to that addition.

Room for one more.

In binary, 254 is 11111110. Add one and the rightmost bit becomes 1: 11111111. That is 255, and it still fits in eight bits.

The sum needs a ninth bit.

255 + 1 is 256. In binary, that is 1 00000000: a 1 in the next position, worth 256, followed by eight zeroes.

The full answer is correct, but it needs nine bits. When we keep only the rightmost eight, the stored result is 0. This is called wraparound.

The extra bit is the carry out of the byte. Here it is 1. For an addition that fits in eight bits, it is 0. You can reconstruct the full sum as carry × 256 + stored result.

A carry can stay inside the byte.

Try starting at 15: 00001111. Adding one gives 16: 00010000. The addition carries into the next position, but all of its bits still fit inside the byte. The carry out of the whole byte is 0.

This explorer shows unsigned arithmetic with an eight-bit stored result. A processor’s instructions decide how to record carry in its flags; those rules come later.