Skip to topic
    ← Back to course topics

    Underflow and overflow — AQA A-Level Computer Science

    Overflow occurs when the magnitude of an arithmetic result exceeds the maximum representable value for the allocated bit width, corrupting the sign or leading bits. Underflow occurs when a floating-point value is too close to zero to be represented using the available bits in the exponent, causing the value to round down to zero.

    Underflow and overflow explained

    Underflow and overflow are errors that occur when a floating point calculation produces a result the representation cannot hold.

    Read the full explanation

    Overflow happens when the magnitude of a number is too large for the exponent field to represent; the result cannot be stored and is typically reported as an error or infinity depending on the system. Underflow happens when the magnitude is too small, so the exponent is too negative to represent, and the value is rounded to zero or lost. Both are limits of the finite exponent range. Overflow is usually the result of multiplying very large numbers or of repeated addition that grows past the largest representable value. Underflow is more common when very small numbers are multiplied together or when a very small number is divided by a large one. Explain each condition in terms of the exponent range and state the consequence.

    Your focus

    1. Explain underflow and overflow and describe the circumstances in which they occur.

    Which command word is this?

    Set out the cause and effect clearly. For overflow/underflow, you must explain both the mechanical reason (e.g., exponent too negative) and the functional consequence (e.g., value rounds to zero or wraps to negative).

    Underflow and overflow exam tips

    Topic Overview

    Underflow and overflow are fundamental computational errors that occur due to the finite nature of computer storage. In any digital system, processors allocate a fixed number of bits to store integers, fixed-point values, or floating-point numbers. When mathematical operations generate a result that lies outside the range of values that the allocated bits can express, the computer cannot accurately represent the outcome.

    Understanding these boundaries is essential in Computer Science because unhandled overflow and underflow cause critical logical bugs, security vulnerabilities, or catastrophic system failures in safety-critical software. Mastery of this topic connects directly to two's complement arithmetic, floating-point normalisation, and the role of the processor's status register in flagging arithmetic exceptions.

    Key Concepts
    • →Arithmetic Overflow: Occurs when a calculation generates a number whose magnitude exceeds the maximum limit of the allocated bit width, causing higher-order bits to be lost or the sign bit to flip incorrectly.
    • →Arithmetic Underflow: Occurs when a non-zero calculation produces a result too close to zero for the available precision or exponent range to store, resulting in the value rounding to zero.
    • →Processor Status Register: The CPU hardware includes dedicated flag bits, such as the Overflow Flag (V) and Carry Flag (C), which trigger interrupts or status checks immediately when an arithmetic operation fails.
    • →Floating-Point Limitations: Overflow in floating-point systems occurs when the positive exponent exceeds its maximum value; underflow occurs when the negative exponent falls below its minimum value.
    Marking Points
    • Defines overflow as a magnitude too large for the exponent to represent.
    • Defines underflow as a magnitude too small for the exponent to represent, so the value is lost or rounded to zero.
    • Identifies that both conditions arise because the exponent range is finite.
    • Gives a plausible circumstance for each, such as multiplying large numbers for overflow and very small numbers for underflow.
    • States the consequence of each, such as an error or infinity for overflow and loss of value for underflow.
    Examiner Tips
    • 💡Use the words large and small magnitude explicitly to distinguish the two conditions.
    • 💡Name the exponent as the cause of each condition.
    • 💡Give one example calculation for each condition.
    • 💡Always state the boundary limits of the data type before answering: for an n-bit two's complement integer, the valid range is -2^(n-1) to 2^(n-1) - 1.
    • 💡When explaining floating-point underflow, explicitly mention that the exponent is the limiting factor: state that the required negative exponent is smaller than the minimum representable exponent.
    • 💡Use standard phrases like 'flushed to zero' or 'loss of precision' when detailing the exact consequences of arithmetic underflow in extended response questions.
    Common Mistakes
    • Confuses overflow with underflow by describing a very large result as underflow; overflow is the large-magnitude case.
    • Says underflow produces an error message in all cases; underflow usually silently rounds the value to zero.
    • Describes the problem as a mantissa limit rather than an exponent limit; the range problem comes from the exponent.
    • Treating negative overflow as underflow: Students often confuse absolute magnitude with number line direction, assuming that an answer falling below the minimum negative integer (e.g., -129 in an 8-bit signed system) is 'underflow' when it is actually negative overflow.
    • Confusing the carry bit with the overflow flag: In unsigned binary, an end-carry represents overflow; in signed two's complement, an end-carry does not automatically mean overflow—overflow only occurs if the carry into the sign bit differs from the carry out of the sign bit.
    • Assuming division by zero is underflow: Dividing by zero produces an undefined or infinite mathematical result (triggering a zero-division exception), whereas underflow specifically describes non-zero results too small to measure.
    Revision Plan
    1. 1Day 1: Review two's complement integer limits for 8-bit and 16-bit integers, practicing manual binary additions that trigger sign-bit flips.
    2. 2Day 2: Master the Carry vs. Overflow distinction and learn how the CPU status register detects two's complement overflow.
    3. 3Day 3: Practice calculating the maximum and minimum representable values for floating-point systems using custom mantissa and exponent bit lengths.
    4. 4Day 4: Work through AQA past paper exam questions specifically focused on identifying overflow in arithmetic logic unit (ALU) operations.
    5. 5Day 5: Review real-world case studies (e.g., Ariane 5 rocket failure) to write strong, context-rich explanatory answers for 4-mark and 6-mark questions.
    Exam Question Types
    • 📋Calculation questions: Adding two binary numbers in two's complement and explicitly proving whether overflow has taken place by examining sign bits.
    • 📋Range determination questions: Stating the maximum positive and minimum negative values of a given fixed-point or floating-point format to identify edge cases.
    • 📋Scenario-based explanation questions: Describing what will happen when a loop variable or sensor reading surpasses the upper limit of its data type.
    Command Word Expectations (AQA)
    Explain

    Set out the cause and effect clearly. For overflow/underflow, you must explain both the mechanical reason (e.g., exponent too negative) and the functional consequence (e.g., value rounds to zero or wraps to negative).

    State

    Provide a brief, factual answer without explanation. If asked to state whether overflow occurred, answer 'Yes' or 'No' and provide the binary pattern if requested.

    Show

    Provide all intermediate steps of arithmetic working, including individual column carry bits and final conversions to demonstrate how the error manifested.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing negative overflow with underflow by assuming that a very large negative number that cannot be stored results in underflow.
    ❌ Weak Answer (Loses Marks):Underflow happens when the result is too negative to fit in the 8 bits provided.
    Example improved answer:Underflow occurs when a calculated floating-point value is non-zero but has a magnitude too small (too close to zero) to be represented within the available negative exponent range, causing it to be stored as absolute zero. A number that is too negative to fit constitutes negative overflow.
    Examiner Tip: Always remember: overflow is about magnitude (both positive and negative values that are too large), while underflow is strictly about values too close to zero.
    Pitfall: Failing to explain how two's complement overflow is detected using sign bit changes.
    ❌ Weak Answer (Loses Marks):Overflow happens because there is an extra carry bit on the left that falls off the edge.
    Example improved answer:In two's complement representation, overflow occurs when two positive numbers are added together and yield a negative result (sign bit 1), or when two negative numbers are added together and yield a positive result (sign bit 0), indicating that the carry into the sign bit differed from the carry out.
    Examiner Tip: In AQA questions involving binary addition, always check the sign bit of both operands and the result to prove whether overflow occurred.
    Step-by-Step Worked Solutions

    Question: Add the two 8-bit two's complement integers 01010000 and 01011000. Show all binary working, state the denary values of the operands and the result, and explain whether overflow has occurred.

    1. 1.Step 1: Convert operands to denary. 01010000 = 64 + 16 = +80. 01011000 = 64 + 16 + 8 = +88.
    2. 2.Step 2: Perform binary addition column by column: 01010000 + 01011000 = 10101000 (Carry generated into bit 7 / the sign bit).
    3. 3.Step 3: Convert the 8-bit two's complement result 10101000 to denary: -128 + 32 + 8 = -88.
    4. 4.Step 4: Analyze sign bits and range. Adding two positive numbers (+80 and +88) should equal +168. The maximum representable positive value in an 8-bit two's complement system is +127 (2^7 - 1).
    5. 5.Step 5: Conclude overflow status. Overflow has occurred because the result exceeds +127, wrapping around into a negative number (-88) due to a carry into the sign bit.
    Final Answer: Binary result: 10101000 (denary -88). Overflow has occurred because the true sum (+168) exceeds the maximum representable limit of +127 for an 8-bit signed integer, causing a positive addition to produce a negative result.

    Question: A floating-point system uses a 5-bit normalised mantissa and a 3-bit exponent, both in two's complement. The smallest positive normalised value currently stored is divided by 2. Explain why this operation causes underflow.

    1. 1.Step 1: Determine the smallest positive normalised mantissa. In two's complement normalised form, a positive mantissa starts with 0.1, so the 5-bit mantissa is 0.1000 (which equals 0.5 in denary).
    2. 2.Step 2: Determine the range of the 3-bit two's complement exponent. A 3-bit two's complement value can represent integers from -4 (100) to +3 (011).
    3. 3.Step 3: State the smallest representable positive value: 0.1000 * 2^(-4) = 0.5 * (1/16) = 0.03125.
    4. 4.Step 4: Calculate the required exponent when dividing by 2: Dividing by 2 reduces the exponent by 1, requiring an exponent of -4 - 1 = -5.
    5. 5.Step 5: Conclude why underflow occurs: The minimum exponent the system can represent is -4. The required exponent -5 cannot be represented in 3 bits, meaning the value is too small to be represented and underflows to zero.
    Final Answer: Underflow occurs because dividing the smallest positive value requires an exponent of -5, which falls outside the representable range of a 3-bit two's complement exponent (-4 to +3). The system cannot represent the number and flushes it to zero.
    Active Recall Memory Test
    What is the formal definition of arithmetic overflow?
    Key Fact: Overflow occurs when the result of a calculation produces a value that exceeds the maximum numerical range that can be stored in the assigned number of bits.
    What is the formal definition of arithmetic underflow in floating-point systems?
    Key Fact: Underflow occurs when a non-zero calculation produces a number with a magnitude so small (too close to zero) that the negative exponent cannot represent it, causing it to round down to zero.
    How can you instantly detect two's complement overflow when adding two numbers of the same sign?
    Key Fact: If adding two positive numbers produces a negative result, or adding two negative numbers produces a positive result, overflow has occurred.
    What CPU component tracks whether an arithmetic operation has caused an overflow or carry?
    Key Fact: The Status Register (or Condition Code Register / Flags Register), using the Overflow (V) and Carry (C) flag bits.
    Frequently Asked Questions
    Why does two's complement overflow cause a positive number to turn negative?
    In two's complement, the most significant bit (MSB) has a negative place value (e.g., -128 in an 8-bit number). When the sum of two positive numbers exceeds the maximum positive limit, the carrying bits spill into this MSB position. Because the computer interprets an MSB of 1 as negative, the value immediately wraps around to a negative number.
    Can underflow occur in integer arithmetic?
    Strictly speaking, in the context of the AQA Computer Science specification, underflow occurs in floating-point systems when a value is too small to be represented. In integer arithmetic, numbers smaller than 1 either round down to zero during integer division (truncation) or trigger an integer underflow condition if a program incorrectly uses that term to describe negative overflow. For exam purposes, always associate underflow with floating-point exponents and values too close to zero.
    What is the difference between arithmetic underflow and stack underflow?
    Arithmetic underflow refers to mathematical values becoming too small to store in floating-point registers. Stack underflow is an entirely different data structure error that occurs when a program attempts to pop an item from an empty call stack or data stack. Do not confuse the two in exam answers.
    What famous real-world disaster was caused by an integer overflow?
    The maiden flight of the Ariane 5 rocket (Flight 501) in 1996 failed due to an overflow. A 64-bit floating-point velocity measurement was converted into a 16-bit signed integer. The value was greater than 32,767 (the maximum 16-bit signed value), causing an unhandled hardware overflow exception that triggered self-destruction of the rocket.
    How do programmers prevent overflow from corrupting their software?
    Programmers prevent overflow by choosing appropriate data types with sufficient bit widths (such as 64-bit integers instead of 32-bit), implementing runtime bounds checking, and using languages or compiler flags that throw exceptions instead of silently wrapping values around. Additionally, libraries supporting arbitrary-precision arithmetic can dynamically allocate more memory as numbers grow.