Subtraction
Subtraction finds what is left when you take an amount away, or how far apart two numbers are. It undoes addition, which gives you a free way to check every answer, and its column method uses borrowing, the mirror image of carrying.
Words and symbols
In , the number you start from (52) is the minuend, the number taken away (17) is the subtrahend, and the result (35) is the difference. You can read subtraction two ways:
- Take away: you had 52 stickers and gave away 17, so 35 are left.
- Difference (compare): 52 is 35 more than 17. On the number line, 35 is the distance from 17 to 52.
Subtraction undoes addition
Subtraction and addition are inverse operations: one undoes the other.
This is the best habit in arithmetic: check a subtraction by adding the answer back. If you get the minuend, the answer is right.
Unlike addition, order matters. is 35, but is , a negative number (see Signed Numbers). Grouping matters too: , but . Subtraction is neither commutative nor associative.
a, b = 52, 17
d = a - b
print("difference:", d)
print("check by adding:", d + b == a)
print("reversed order:", b - a)
print((10 - 4) - 3, 10 - (4 - 3))difference: 35
check by adding: True
reversed order: -35
3 9
Column subtraction with borrowing
Line the numbers up by place value and subtract column by column from the right. When the top digit is smaller than the bottom digit, borrow: take 1 from the next column to the left, which is worth 10 in the current column.
6 ¹3 ¹2 (after borrowing)
7 4 2
− 2 8 6
---------
4 5 6
ones: 2 < 6, borrow from the tens: 12 − 6 = 6 (tens digit 4 becomes 3)
tens: 3 < 8, borrow from the hundreds: 13 − 8 = 5 (hundreds 7 becomes 6)
hundreds: 6 − 2 = 4
check: 456 + 286 = 742 ✓Zeros make borrowing look harder, because you have to borrow across them: in , the ones borrow from the tens, which first borrow from the hundreds. 400 becomes 3 hundreds, 9 tens and 10 ones, and then , , , giving 263.
Here is the algorithm in code, printing every borrow:
def column_subtract(a, b): # assumes a >= b >= 0
da = [int(c) for c in str(a)][::-1]
db = [int(c) for c in str(b)][::-1] + [0] * (len(str(a)) - len(str(b)))
out, borrow = [], 0
for i, (x, y) in enumerate(zip(da, db)):
x -= borrow
if x < y:
x += 10
borrow = 1
else:
borrow = 0
out.append(x - y)
print(f"column {i}: {x} - {y} = {x - y}" + (" (borrowed)" if borrow else ""))
return int("".join(map(str, reversed(out))))
print("742 - 286 =", column_subtract(742, 286))column 0: 12 - 6 = 6 (borrowed)
column 1: 13 - 8 = 5 (borrowed)
column 2: 6 - 2 = 4
742 - 286 = 456
Mental subtraction tricks
- Count up (shopkeeper's method): . From 368, , , . Total climbed: 632.
- Round and adjust: . (Taking away 30 took away one too many, so give it back.)
- Shift both numbers: the difference doesn't change if you add the same amount to both. .
The last trick is how you dodge borrowing entirely.
Differences in data
Subtracting neighbours in a list shows how much something changed each step. Programmers call these deltas:
balance = [120, 95, 140, 140, 88] # account balance at the end of each day
changes = [balance[i] - balance[i - 1] for i in range(1, len(balance))]
print("daily change:", changes)
print("total change:", balance[-1] - balance[0], "=", sum(changes))daily change: [-25, 45, 0, -52]
total change: -32 = -32
The daily changes always add up to "last minus first": everything in between cancels.
In software
- Elapsed time: a game measures the time since the last frame as
now - previous(often calleddt) and moves objects by . - Distances and sizes: the width of a box on screen is
right - left; the number of items from indexiup to (not including)jisj - i. - Diffs and change detection: version control, stock charts and sensor dashboards are built on differences between successive values.
- Unsigned integers: in languages like C or Rust, subtracting a bigger unsigned number from a smaller one does not give a negative answer. It wraps around or crashes; see Integer Overflow.
Exercises
Exercise 1: Borrowing
Compute by hand and check by adding.
Answer
3 664
Solution
ones: 0 < 6, borrow from tens (tens 5 → 4): 10 − 6 = 4
tens: 4 < 8, borrow from hundreds (0 → borrow from thousands: 6 → 5, hundreds become 10, then 9): 14 − 8 = 6
hundreds: 9 − 3 = 6
thousands: 5 − 2 = 3
result 3 664; check 3 664 + 2 386 = 6 050 ✓Exercise 2: Count up
Find by counting up.
Answer
753
Solution
. Total climbed: .
Exercise 3: Shift both numbers
Rewrite as an easier subtraction with the same answer, then solve it.
Answer
Solution
Add 3 to both numbers so the subtrahend becomes a round 400: and . The difference is unchanged: .
Exercise 4: Biggest drop
Temperatures at noon for a week were 18, 21, 17, 12, 15, 15, 9. Write code that finds the day-to-day changes and the biggest single drop.
Answer
Changes: 3, −4, −5, 3, 0, −6. The biggest drop is 6 degrees (from 15 to 9).
Solution
The biggest drop is the most negative change, so take min of the changes.
temps = [18, 21, 17, 12, 15, 15, 9]
changes = [temps[i] - temps[i - 1] for i in range(1, len(temps))]
print(changes)
print("biggest drop:", -min(changes))[3, -4, -5, 3, 0, -6]
biggest drop: 6
Test yourself
How do you check that is correct?
- Check that
- Check that
- Check that
- Subtraction cannot be checked
What is ?
- 136
- 146
- 264
- 164
Which is true?
- for all numbers
- for all numbers
- Adding the same number to and leaves unchanged
- Subtraction never gives a negative number