A website runs on 5 servers, and on any given day each one has a 2% chance of failing, independently of the others. What's the chance that at least one fails today? It's tempting to say 5 × 2% = 10%. That's close but wrong, and the reasoning behind it breaks badly with 60 servers: 60 × 2% = 120%, which is impossible.
Three rules combine probabilities correctly: not, or and and. Each comes straight from counting outcomes in a sample space, so you'll see each one on the two-dice grid before using it. Together they answer most everyday probability questions, including the server one.
What you need first: outcomes, events and sample spaces.
Key terms
- Complement: "not A", written Aᶜ. Every outcome not in A.
- Union: "A or B" (or both), written A ∪ B.
- Intersection: "A and B" (both at once), written A ∩ B.
- Mutually exclusive (or disjoint): events that can't happen together, such as "total is 2" and "total is 12".
- Independent: events where knowing one happened doesn't change the probability of the other, such as two separate coin tosses.
Rule 1: not
Every outcome is either in A or not in A, never both. So the two probabilities add up to 1:
P(not A) = 1 − P(A)
For two dice, P(doubles) = 6/36, so P(not doubles) = 30/36. The complement rule is simple, but it's the key to the hardest-looking questions below.
Rule 2: or
What's the chance that two dice give a total of at least 10 or doubles? Here are both events on the grid of 36 outcomes. Before you look, think about whether any outcome could be in both.
import numpy as np
import matplotlib.pyplot as plt
from itertools import product
dice = list(product(range(1, 7), repeat=2))
high = {o for o in dice if sum(o) >= 10}
doubles = {o for o in dice if o[0] == o[1]}
fig, ax = plt.subplots(figsize=(6, 6))
for o in dice:
if o in high and o in doubles:
colour, label = "#1c1917", "both"
elif o in high:
colour, label = "#c2410c", "≥10"
elif o in doubles:
colour, label = "#0f766e", "dbl"
else:
colour, label = "#fbe9dc", ""
ax.add_patch(plt.Rectangle((o[0] - 0.45, o[1] - 0.45), 0.9, 0.9, color=colour))
ax.text(o[0], o[1], label, ha="center", va="center", color="white", fontsize=11)
ax.set_xlim(0.4, 6.6)
ax.set_ylim(0.4, 6.6)
ax.set_xticks(range(1, 7))
ax.set_yticks(range(1, 7))
ax.set_xlabel("First die")
ax.set_ylabel("Second die")
ax.set_title("Total ≥ 10 (orange), doubles (green), both (black)")
ax.set_aspect("equal")
plt.show()
{o for o in dice if ...} builds a set of outcomes, so o in high and o in doubles checks whether an outcome is in both events.
There are 6 high outcomes and 6 doubles, but the answer isn't 12/36: (5, 5) and (6, 6) are in both events. Adding 6 + 6 counts those two squares twice. Subtract the overlap once:
6 + 6 − 2 = 10 outcomes, so P(high or doubles) = 10/36
In probabilities, that's the addition rule:
P(A or B) = P(A) + P(B) − P(A and B)
p_high, p_doubles = len(high) / 36, len(doubles) / 36
p_both = len(high & doubles) / 36
print("addition rule:", round(p_high + p_doubles - p_both, 4))
print("direct count: ", round(len(high | doubles) / 36, 4))
addition rule: 0.2778
direct count: 0.2778
For Python sets, & keeps outcomes in both (and), and | keeps outcomes in either (or). Both routes give the same answer.
If two events are mutually exclusive, they have no overlap, so P(A and B) = 0 and you can simply add. P(total is 2 or total is 12) = 1/36 + 1/36 = 2/36, because no outcome totals both.
Rule 3: and
Toss a coin and roll a die. What's the chance of heads and a six? There are 2 × 6 = 12 equally likely outcomes, and only one of them is (heads, 6), so the answer is 1/12. Notice that 1/12 = 1/2 × 1/6. That's the multiplication rule for independent events:
P(A and B) = P(A) × P(B), if A and B are independent
Why multiply? Think of 1,200 tosses-and-rolls. About half, 600, give heads. Of those 600, about a sixth, 100, also give a six. Taking a sixth of a half gives a twelfth.
The rule needs independence: the coin can't affect the die. When events affect each other, it gives the wrong answer. Draw two cards from a pack without putting the first back: P(first is an ace) = 4/52, but if it was an ace, only 3 aces are left among 51 cards, so P(both aces) = 4/52 × 3/51, not 4/52 × 4/52. Handling that "given the first was an ace" properly is the subject of the next module, on conditional probability.
Independent is not the same as mutually exclusive. Mutually exclusive events can't happen together, so they're strongly linked: if one happens, the other definitely didn't. Independent events can happen together, and one tells you nothing about the other.
The "at least one" trick
Back to the servers. "At least one fails" includes one failure, two failures, three, four or all five, with overlaps everywhere. Counting those directly is painful. The complement is easy: "at least one fails" is the opposite of "none fail".
- P(one server survives) = 1 − 0.02 = 0.98 (not rule)
- P(all 5 survive) = 0.98⁵ (and rule, since failures are independent)
- P(at least one fails) = 1 − 0.98⁵ (not rule again)
for servers in [5, 20, 60]:
exact = 1 - 0.98 ** servers
print(f"{servers:>2} servers: at least one fails {exact:.3f} (naive {servers * 0.02:.2f})")
5 servers: at least one fails 0.096 (naive 0.10)
20 servers: at least one fails 0.332 (naive 0.40)
60 servers: at least one fails 0.702 (naive 1.20)
With 5 servers, the naive 10% is close to the true 9.6%, because overlaps are rare. With 60 servers, the naive answer is an impossible 120%, while the correct answer is about 70%. Adding probabilities of events that can overlap always overcounts.
The same trick answers a classic Ludo question: what's the chance of at least one six in 4 rolls? It's 1 − (5/6)⁴, a little over a half.
Checking the rules by simulation
Every rule can be checked by trying the experiment many times. Simulate 100,000 rounds of 4 die rolls:
rng = np.random.default_rng(4)
rolls = rng.integers(1, 7, size=(100_000, 4))
simulated = (rolls == 6).any(axis=1).mean()
print(f"simulated {simulated:.4f} exact {1 - (5 / 6) ** 4:.4f}")
simulated 0.5189 exact 0.5177
rolls == 6marks every six with True..any(axis=1)asks, for each round of 4 rolls, whether any roll was a six..mean()gives the share of rounds with at least one six.
The simulation agrees with the rule to two or three decimal places. When you aren't sure a calculation is right, a simulation like this is the quickest check, and simulate probability with Python builds the habit.
Where machine learning uses these rules
- Class probabilities add to 1: a classifier's classes are mutually exclusive and cover every possibility, so
predict_probafor each example sums to 1, and P(not spam) = 1 − P(spam). - Naive Bayes multiplies the probabilities of each word in an email, pretending words are independent. The pretence is the "naive" part.
- Ensembles and systems: if each of 3 independent checks misses a fraud 10% of the time, all three miss it 0.1³ = 0.1% of the time.
- Reliability: the "at least one" trick sizes systems: how many replicas keep the chance of total failure below one in a million?
Common mistakes
- Adding probabilities that overlap. Use the addition rule or the complement.
- Multiplying probabilities that aren't independent. Cards without replacement and related customers break the rule.
- Confusing mutually exclusive with independent. Exclusive events can't both happen; independent events don't influence each other.
- Getting a probability above 1. It always means something was counted twice.
Practice
- P(rain tomorrow) = 0.3. What's P(no rain tomorrow)?
Show the answer
1 − 0.3 = 0.7.
- In a class, 40% of students play cricket, 25% play football and 10% play both. What share play cricket or football?
Show the answer
0.40 + 0.25 − 0.10 = 0.55, so 55%.
- Predict, then check: what's the chance of at least one six in 24 rolls of two dice, where a "six" now means double six?
Show the answer
Each throw gives double six with probability 1/36, so the answer is 1 − (35/36)²⁴, just under a half. This is a famous 17th-century gambling puzzle that gamblers expected to be over a half.
print(round(1 - (35 / 36) ** 24, 4))
0.4914
- Are "the first die shows 6" and "the total is 7" independent? Check by counting.
Show the answer
P(first is 6) = 6/36 = 1/6. P(total is 7) = 6/36 = 1/6. P(both) = 1/36, only (6, 1). And 1/6 × 1/6 = 1/36, so yes, they're independent, which surprises most people. Any first die can still make 7 with exactly one second-die value, so knowing the first die doesn't change the chance of 7.
first_6 = {o for o in dice if o[0] == 6}
total_7 = {o for o in dice if sum(o) == 7}
print(round(len(first_6 & total_7) / 36, 4), round((len(first_6) / 36) * (len(total_7) / 36), 4))
0.0278 0.0278
- A student says "P(heads) = 0.5 and P(tails) = 0.5, and they're mutually exclusive, so they must be independent too." What's wrong?
Show the answer
Mutually exclusive events with non-zero probabilities are never independent. If the coin shows heads, you know for certain it doesn't show tails, so knowing one completely changes the probability of the other. P(heads and tails) = 0, but 0.5 × 0.5 = 0.25.
Interview questions
State the addition rule and when it simplifies.
P(A ∪ B) = P(A) + P(B) − P(A ∩ B). The subtraction removes outcomes counted twice. If A and B are mutually exclusive, P(A ∩ B) = 0 and the rule becomes P(A ∪ B) = P(A) + P(B).
What's the difference between independent and mutually exclusive events?
Independent events satisfy P(A ∩ B) = P(A)P(B): one occurring gives no information about the other. Mutually exclusive events satisfy P(A ∩ B) = 0: they can't occur together. Two events with positive probabilities can't be both, because exclusivity makes each highly informative about the other.
Key takeaways
- Not: P(not A) = 1 − P(A).
- Or: P(A or B) = P(A) + P(B) − P(A and B); just add when the events can't overlap.
- And: P(A and B) = P(A) × P(B), only when A and B are independent.
- For "at least one", use 1 − P(none), which needs only the not and and rules.
- Mutually exclusive and independent are different ideas, and simulation is a quick way to check any rule.
Frequently asked questions
What's the addition rule for three events?
Add the three, subtract the three pairwise overlaps, then add back the triple overlap, because subtracting removed it once too often. This pattern is called inclusion-exclusion.
How do I know if events are independent?
Either from how the experiment works (separate coins, separate dice) or by checking whether P(A and B) = P(A) × P(B) in data. Real-world events, such as two customers from one household churning, are often not independent.
What if events aren't independent?
Then P(A and B) = P(A) × P(B given A). The "given A" part is conditional probability, the subject of the next module.
What to learn next
- Check these rules with experiments in simulate probability with Python.
- Revisit counting in permutations and combinations.
- See how Naive Bayes multiplies probabilities in Naive Bayes classifier.