Difference Between Overflow Flag (OF) and Carry Flag (CF): Meaning + Examples

Difference Between Overflow Flag (OF) and Carry Flag (CF): Meaning + Examples

Verified Sources
Sep 12, 2026

In typical CPU instruction-sets (notably x86), the Carry Flag (CF) and the Overflow Flag (OF) both relate to “incorrect results” but for different interpretations of the data.

  • Carry Flag (CF) is about unsigned magnitude: did the operation generate a carry out (addition) or a borrow (subtraction) beyond the fixed bit-width?
  • Overflow Flag (OF) is about signed range (two’s complement): did the operation produce a result that is outside the representable signed range for the operand width?

Mermaid intuition: CF vs OF correspond to different “truth conditions” for the same bit-pattern result.

Important: OF and CF can be set independently. That’s why learning their exact meaning matters for correctness in both signed and unsigned algorithms.

Flags tutorial: Carry vs Overflow (practical examples)

Key definitions (x86-style semantics)

Carry Flag (CF)

  • For addition of nn-bit operands, CF is set if the full (mathematically correct) sum exceeds 2n12^n-1—i.e., there is a carry out of the most significant bit.
  • For subtraction, CF is set if a borrow is needed in the unsigned sense.

Overflow Flag (OF)

  • For addition of two’s-complement signed nn-bit integers, OF is set if the signed result is outside [2n1,2n11][-2^{n-1}, 2^{n-1}-1].
  • Equivalently: OF becomes 1 when adding two values with the same sign produces a result with the opposite sign (for fixed-width two’s complement).

Work an example in both signed and unsigned interpretations

  1. 1
    Step 1

    Decide the operand size nn (let’s use 8-bit). Then results wrap modulo 2n2^n in the register.

  2. 2
    Step 2

    Do the math using unbounded integers to see whether a carry out occurred (unsigned) and whether the signed range is violated.

  3. 3
    Step 3

    CF=1 if there is a carry out beyond 2n12^n-1 for addition, or a borrow for subtraction.

  4. 4
    Step 4

    OF=1 if the signed two’s-complement result cannot be represented in nn bits (range violation).

  5. 5
    Step 5

    It’s common to see: CF=1, OF=0; CF=0, OF=1; or both 1—depending on the operands.

Example 1 (Carry set, Overflow not set): unsigned overflow, but signed still valid

Let’s use 8-bit addition:

  • Operands: 0xFF0xFF and 0x010x01
  • Binary:
    • 0xFF=2550xFF = 255 unsigned, 1-1 signed (two’s complement 8-bit)
    • 0x01=10x01 = 1 unsigned, +1+1 signed

Compute the raw sum

255+1=256255 + 1 = 256

Registers keep only the low 8 bits: 256mod256=0x00256 \bmod 256 = 0x00

Unsigned check → CF

Unsigned sum exceeded 255255, so there is a carry out:

  • CF = 1

Signed check → OF

Signedly: 1+1=0-1 + 1 = 0 which is representable in 8-bit signed range:

  • OF = 0

So this produces:

  • Result: 0x000x00
  • CF = 1
  • OF = 0

Mermaid summary:

Example 2 (Overflow set, Carry not set): signed overflow, but unsigned still in range

Use 8-bit addition:

  • Operands: 0x7F0x7F and 0x010x01
  • Interpretations:
    • 0x7F=1270x7F = 127 unsigned, +127+127 signed
    • 0x01=10x01 = 1 unsigned, +1+1 signed

Compute the raw sum

127+1=128127 + 1 = 128

In 8-bit registers: 128mod256=0x80128 \bmod 256 = 0x80

Unsigned check → CF

Unsigned maximum is 255255, and 128255128 \le 255, so no carry out:

  • CF = 0

Signed check → OF

8-bit signed range is [128,127][-128, 127]. But the mathematical signed result is 128128, which is out of range:

  • OF = 1

So:

  • Result: 0x800x80
  • CF = 0
  • OF = 1

Mermaid summary:

Rule of thumb

Think of CF as unsigned carry/borrow, and OF as signed range overflow. Same bit result, different meaning depending on whether you treat operands/results as signed or unsigned.

Don’t use the wrong flag for comparisons

If you’re doing unsigned arithmetic, CF/CF-based logic is relevant; for signed arithmetic, OF (plus sign bit) matters. Using the wrong flag often breaks edge cases like 0x7F+10x7F+1 or 0xFF+10xFF+1.

How to decide CF vs OF during debugging

Unsigned vs signed

1) Identify signedness intent

Are you interpreting operands as unsigned (0..2n12^n-1) or signed two’s complement (2n1-2^{n-1}..2n112^{n-1}-1)?"

Look for CF

2) Check carry/borrow

CF indicates carry/borrow out of the nn-bit boundary."

Look for OF

3) Check signed range

OF indicates whether the signed result can’t be represented in nn bits."

Test with edges

4) Validate with a concrete example

Try patterns near 0x7F/0x800x7F/0x80 and 0xFF/0x000xFF/0x00 to confirm understanding."

Flag behavior for two 8-bit addition cases

Which flags are set for each example.

Common questions

Carry vs Overflow Quick Checks

1 / 4
Question · Term

CF means what for addition?

Click to reveal
Answer · Definition

CF=1 if unsigned sum produces a carry out beyond nn bits.

Knowledge Check

Question 1 of 4
Q1Single choice

For 8-bit addition 0xFF + 0x01, what are CF and OF?

Explore Related Topics

1

Differences Between Leaky Bucket and Token Bucket Algorithms (Traffic Shaping vs Rate Limiting)

2

8085 Microprocessor Flags: Correct Answer and Conceptual Explanation

The 8085 microprocessor’s flag register contains five active status flags that are automatically set after arithmetic and logical operations.

  • The 8‑bit flag register uses only five bits: Sign (S), Zero (Z), Auxiliary Carry (AC), Parity (P), and Carry (CY).
  • These flags guide conditional branch instructions such as jump‑on‑zero or jump‑on‑carry.
  • Although the register is 8 bits wide, the remaining three bits are unused/reserved, a common source of exam mistakes.
  • The Auxiliary Carry flag is especially important for BCD arithmetic.
3

Process in Operating Systems and the Contrast Between Interprocess Communication Models

A process is the active execution of a program with its own state, resources, and PCB, and operating systems use it for scheduling, protection, and cooperation via interprocess communication (IPC); the two primary IPC models—shared memory and message passing—differ in data movement, synchronization, kernel involvement, and suitability for local versus distributed use.

  • PCB stores a process’s state, registers, scheduling info, and resource data, enabling context switches.
  • Standard process lifecycle: new → ready → running → waiting/blocked → terminated.
  • IPC is required for cooperating processes because each has an isolated address space.
  • Shared memory offers high performance for large local data but demands explicit synchronization.
  • Message passing provides easier, safer communication and works well across machines, at the cost of higher kernel overhead.