Binary Overflow Calculator
Check whether binary addition or subtraction causes signed or unsigned overflow. Select the bit width and number interpretation to compare the exact mathematical result with the value actually stored in the fixed-width binary result.
What Is Binary Overflow?
Binary overflow occurs when the exact mathematical result cannot be represented using the available number of bits. Fixed-width binary systems can represent only a limited range of numeric values.
When a result exceeds that range, only the low-order bits may remain in the storage location. The stored bit pattern can therefore represent a very different value from the intended mathematical result.
Overflow rules depend on whether the bit pattern is interpreted as unsigned binary or signed two’s complement.
Signed vs Unsigned Overflow
Unsigned Overflow
An unsigned n-bit value ranges from 0 through 2^n – 1. Addition overflows when the result exceeds the maximum value, while subtraction underflows when the result becomes negative.
Signed Overflow
A signed n-bit two’s-complement value ranges from -2^(n-1) through 2^(n-1)-1. Overflow occurs when a result lies outside this interval.
Binary Overflow Range Table
| Width | Unsigned Range | Signed Range |
|---|---|---|
| 4 bits | 0 to 15 | -8 to 7 |
| 8 bits | 0 to 255 | -128 to 127 |
| 12 bits | 0 to 4095 | -2048 to 2047 |
| 16 bits | 0 to 65535 | -32768 to 32767 |
| 24 bits | 0 to 16777215 | -8388608 to 8388607 |
Worked Example 1: Signed Addition Overflow
Worked Example 2: Unsigned Addition Overflow
Worked Example 3: Signed Subtraction Overflow
Worked Example 4: No Overflow
Carry Out vs Signed Overflow
Carry and signed overflow are not the same condition. Carry-out is particularly useful for unsigned arithmetic, while signed two’s-complement overflow depends on whether the mathematical result exceeds the signed range.
| Condition | Carry Out | Signed Overflow |
|---|---|---|
| Unsigned addition exceeds maximum | Usually yes | Not applicable |
| Positive + positive gives negative stored result | May vary | Yes |
| Negative + negative gives positive stored result | May occur | Yes |
| Result fits signed range | May still occur | No |
Signed Addition Overflow Rule
In two’s-complement addition, signed overflow occurs when two operands with the same sign produce a result with the opposite sign.
Binary Wraparound
Fixed-width arithmetic effectively keeps only the result modulo 2^n. This produces wraparound when the mathematical result is outside the available range.
Overflow vs Underflow
Overflow
A result is too large for the maximum representable value of the selected bit width.
Integer Underflow
In unsigned arithmetic, subtraction can produce a negative mathematical result that cannot be represented, causing modular wraparound.
Floating-point underflow is a different concept involving values too close to zero for a floating-point format and should not be confused with integer wraparound.
Common Binary Overflow Cases
| Mode | Width | Calculation | Exact Result | Overflow? |
|---|---|---|---|---|
| Signed | 4 | 7 + 1 | 8 | Yes |
| Signed | 4 | -8 – 1 | -9 | Yes |
| Signed | 8 | 100 + 20 | 120 | No |
| Signed | 8 | 100 + 40 | 140 | Yes |
| Unsigned | 8 | 200 + 55 | 255 | No |
| Unsigned | 8 | 200 + 56 | 256 | Yes |
| Unsigned | 8 | 5 – 6 | -1 | Yes |
Why Binary Overflow Matters
CPU Arithmetic
Processors perform arithmetic using fixed-width registers, so understanding overflow is essential for interpreting low-level results.
Programming
Integer types have finite ranges. Overflow behavior can affect calculations, counters, indexes and numerical algorithms.
Embedded Systems
Small fixed-width integer types are common in microcontrollers, sensors and hardware interfaces.
Digital Logic
Adder circuits generate carry and overflow information that can be used to detect invalid fixed-width results.
Important Binary Overflow Notes
The same stored bit pattern may represent a different number in signed and unsigned arithmetic.
For signed two’s-complement calculations, carry-out alone does not reliably indicate signed overflow.
This calculator shows both the exact mathematical result and the fixed-width stored result so you can see the effect of wraparound directly.