Simple and Compound Interest
Interest is what you pay to borrow money, or earn by lending or saving it. With simple interest you earn the same amount every period; with compound interest you also earn interest on earlier interest, so the balance grows faster and faster. This lesson gives both formulas, compares them, covers compounding frequency and APR vs APY, and builds an exact savings table with Decimal.
The words
| Term | Meaning |
|---|---|
| principal | the amount borrowed or deposited at the start |
| rate | interest per period, as a decimal (5% per year → ) |
| time | number of periods (usually years) |
| interest | the money added on top |
| amount | at the end |
Simple interest
Interest is computed on the original principal only, the same amount every year:
1000 at 5% simple interest for 3 years: , so . The balance grows in a straight line: +50, +50, +50. Short loans and some bonds work this way.
Compound interest
Each year's interest is added to the balance, and next year's interest is computed on the new, larger balance. Each year multiplies the balance by , just like a repeated percent change:
1000 at 5% compounded yearly for 3 years:
7.63 more than simple interest. Small at first, but the gap widens with time because the growth is exponential:
P, r = 1000, 0.05
print("year simple compound")
for t in [1, 3, 5, 10, 20, 30]:
simple = P * (1 + r * t)
compound = P * (1 + r) ** t
print(f"{t:4} {simple:8.2f} {compound:9.2f}")year simple compound
1 1050.00 1050.00
3 1150.00 1157.63
5 1250.00 1276.28
10 1500.00 1628.89
20 2000.00 2653.30
30 2500.00 4321.94
After 30 years, compound interest has more than quadrupled the money; simple interest has only multiplied it by 2.5.
Compounding more often
Banks often compound monthly or daily. With a yearly rate compounded times a year, each period uses rate , and there are periods:
The more often you compound, the more you earn, but the gain levels off. The yearly growth you actually get is the APY (annual percentage yield, or effective annual rate); the quoted is the APR (nominal rate):
import math
r = 0.06
for name, n in [("yearly", 1), ("quarterly", 4), ("monthly", 12), ("daily", 365)]:
apy = (1 + r / n) ** n - 1
print(f"{name:10} APY = {apy:.4%}")
print(f"{'continuous':10} APY = {math.exp(r) - 1:.4%}")yearly APY = 6.0000%
quarterly APY = 6.1364%
monthly APY = 6.1678%
daily APY = 6.1831%
continuous APY = 6.1837%
The limit as grows without bound is continuous compounding, , where is the number you will meet in Common and Natural Logs.
The rule of 72
How long does money take to double? Roughly years. At 6%, about years (exactly: ). It works for anything growing at a steady percentage: prices under inflation, user counts, even debt.
An exact savings table with Decimal
Real bank code rounds to cents every period, and that rounding must be exact and repeatable. Monthly deposits of 200 into an account paying 4.8% a year, compounded monthly (0.4% a month):
from decimal import Decimal, ROUND_HALF_EVEN
CENT = Decimal("0.01")
monthly_rate = Decimal("0.048") / 12 # exactly 0.004
balance = Decimal("0.00")
for month in range(1, 13):
balance += Decimal("200.00")
interest = (balance * monthly_rate).quantize(CENT, rounding=ROUND_HALF_EVEN)
balance += interest
if month in (1, 2, 3, 12):
print(f"month {month:2}: interest {interest:>5} balance {balance:>8}")
print("deposited:", 12 * Decimal("200.00"), " earned:", balance - 12 * Decimal("200.00"))month 1: interest 0.80 balance 200.80
month 2: interest 1.60 balance 402.40
month 3: interest 2.41 balance 604.81
month 12: interest 9.81 balance 2463.33
deposited: 2400.00 earned: 63.33
In software
- Fintech and banking: loan schedules, savings projections and credit-card interest are compound-interest loops with exact
Decimalrounding at each period, written to match the bank's documented rules to the cent. - Growth modelling: user growth, storage growth and cloud costs that grow by a fixed percentage per month follow . Capacity planning uses it to predict when a disk fills up.
- Retry back-off: exponential back-off (wait 1 s, 2 s, 4 s, …) is "compounding at 100% per retry".
Exercises
Exercise 1: Simple interest
You borrow 2400 at 6% simple interest for 18 months. How much interest do you pay?
Answer
216
Solution
18 months is years. .
Exercise 2: Compound by hand
5000 is invested at 4% compounded yearly. What is it worth after 2 years?
Answer
5408.00
Solution
Or in one step: .
Exercise 3: Rule of 72
Prices rise 3% a year. Roughly how many years until they double? Compare with the exact value.
Answer
About 24 years (exactly about 23.45).
Solution
Rule of 72: years. Exactly, solve : .
import math
print(round(math.log(2) / math.log(1.03), 2))23.45
Exercise 4: When does the disk fill?
A database uses 300 GB and grows 8% per month. The disk holds 1000 GB. Write a loop that finds the first month in which usage exceeds the disk.
Answer
Month 16 (about 1027 GB).
Solution
Multiply by 1.08 each month until the value passes 1000. Check: and .
usage, month = 300.0, 0
while usage <= 1000:
month += 1
usage *= 1.08
print(month, round(usage, 1))16 1027.8
Test yourself
What is the simple interest on 800 at 5% per year for 4 years?
- 40
- 160
- 172.41
- 200
1000 at 10% compounded yearly for 2 years becomes…
- 1200
- 1210
- 1100
- 1020
A loan quotes 12% APR compounded monthly. The APY is…
- exactly 12%
- less than 12%
- about 12.68%
- 144%