Probability calculator (events & Bayes' theorem)

Calculate P(A or B), P(A and B) and P(A | B) for two events, or apply Bayes' theorem to a test result, with a probability tree and Venn diagram.

Drafted with AI writing toolsUpdated Checked examples: 6

How likely A is before seeing the evidence, e.g. how common a condition is.
Chance of seeing the evidence when A is true, e.g. a test's sensitivity.
Chance of seeing the evidence when A is false, e.g. the false-positive rate (1 − specificity).
Try
P(A | B)
P(A | B): 0.091743
Maximum decimal places: 6; Nearest, ties away from zero
P(A and B)
0.009
P(A or B)
0.0991
P(B)
0.0981
P(A | not B)
0.001109
P(not A)
0.99
P(not B)
0.9019
P(neither A nor B)
0.9009
P(exactly one of A, B)
0.0901
Independent?
No

After seeing B, the probability of A moves from 1% to 9.17%. In natural frequencies: of 10,000 cases, about 90 have A and show B, while 891 show B without A. Of the 981 cases showing B, about 90 have A.

Probability tree

0.010.99Anot A0.90.10.090.91A and B0.009A and not B0.001not A and B0.0891not A, not B0.9009
How it's calculated S
  1. Total probability of the evidence

    P(B)=P(B∣A)P(A)+P(B∣Aˉ)P(Aˉ)=0.9×0.01+0.09×0.99=0.0981P(B) = P(B \mid A)P(A) + P(B \mid \bar A)P(\bar A) = 0.9 \times 0.01 + 0.09 \times 0.99 = 0.0981
  2. Bayes' theorem

    P(A∣B)=P(B∣A)P(A)P(B)=0.0090.0981=0.091743P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)} = \frac{0.009}{0.0981} = 0.091743
  3. Addition rule

    P(A∪B)=P(A)+P(B)−P(A∩B)=0.01+0.0981−0.009=0.0991P(A \cup B) = P(A) + P(B) - P(A \cap B) = 0.01 + 0.0981 - 0.009 = 0.0991
  4. Complements

    P(Aˉ)=0.99,P(Bˉ)=0.9019,P(A∪B‾)=0.9009P(\bar A) = 0.99,\quad P(\bar B) = 0.9019,\quad P(\overline{A \cup B}) = 0.9009
  5. Independence check

    P(A)P(B)=0.000981≠P(A∩B)=0.009P(A)P(B) = 0.000981 \ne P(A \cap B) = 0.009

About the probability calculator

For two events A and B, the addition rule gives P(A or B) = P(A) + P(B) − P(A and B), the multiplication rule gives P(A and B) = P(A) × P(B | A), and conditional probability is P(A | B) = P(A and B) / P(B). Bayes' theorem mode runs the conditional the other way: from a prior P(A) and the two evidence rates P(B | A) and P(B | not A), it returns the updated probability P(A | B).

The Bayes default is a screening test for a condition with 1% prevalence, 90% sensitivity and a 9% false-positive rate. A positive result raises the probability from 1% to 9.17%, because in 10,000 people the 90 true positives are outnumbered by 891 false positives.

Enter probabilities from 0 to 1; fractions such as 1/6 are accepted. Two-events mode rejects combinations that cannot exist, such as a P(A and B) larger than P(A) or P(B).

How to calculate probability

When all outcomes are equally likely, P(event) = favorable outcomes ÷ total outcomes. An even number on a fair die has 3 favorable faces out of 6, so P = 3/6 = 0.5. Every probability lies between 0, impossible, and 1, certain; 0.25 means a 25% chance.

Two events combine through the addition, multiplication and conditional rules below. Bayes' theorem, P(A | B) = P(B | A) × P(A) ÷ P(B), turns a conditional probability around, for example from a test's accuracy to the meaning of a positive result.

Probability formulas for two events

  • Complement: P(not A) = 1 − P(A).
  • Addition rule: P(A or B) = P(A) + P(B) − P(A and B). The overlap is subtracted because adding the two counts it twice.
  • Multiplication rule: P(A and B) = P(A) × P(B | A), which becomes P(A) × P(B) for independent events.
  • Conditional probability: P(A | B) = P(A and B) ÷ P(B), defined only when P(B) > 0.

Roll two dice, with A a six on the first and B a six on the second. Both happen with probability 1/6 × 1/6 = 1/36, and at least one six with 1/6 + 1/6 − 1/36 = 11/36, about 0.306.

With independent probabilities 0.5 and 0.4, both events happen with probability 0.2 and at least one with 0.7. Neither happens with 0.3, and exactly one with 0.5.

RelationshipP(A)P(B)P(A and B)P(A or B)P(A given B)
Independent0.50.40.20.70.5
Mutually exclusive0.30.4500.750
Known intersection0.60.50.40.70.8
Known conditional0.60.50.30.80.6

In the last row the known input is P(B | A) = 0.5, so the multiplication rule gives P(A and B) = 0.6 × 0.5 = 0.3.

Independent vs mutually exclusive events

Independent events don't change each other's chances, so P(A and B) = P(A) × P(B): two coin flips, or two dice. Mutually exclusive events can't happen together, so P(A and B) = 0: heads and tails on the same flip.

Two events with positive probabilities can't be both. If A rules out B, learning that A happened drops B's chance to 0, the opposite of independence.

Conditional probability has a direction

P(A | B) and P(B | A) are usually different. In the known-intersection row, P(A | B) = 0.4 ÷ 0.5 = 0.8, but P(B | A) = 0.4 ÷ 0.6 = 0.667.

An overlap also has limits. It can't exceed either probability, and it must be at least P(A) + P(B) − 1. With 0.6 and 0.5 it lies between 0.1 and 0.5, so a stated P(A and B) of 0.7 is impossible.

Bayes' theorem with a worked example

Bayes' theorem updates a prior probability with evidence. Its denominator is the total chance of the evidence: P(B) = P(B | A) P(A) + P(B | not A) P(not A).

Take a condition affecting 1% of people, a test that detects 90% of cases and a 9% false-positive rate, the screening example used by Gigerenzer and colleagues (2007). Out of 10,000 people:

  1. 100 have the condition, and 90 of them test positive.
  2. 9,900 don't, and 891 of them test positive anyway.
  3. Of the 981 positives, 90 are true: 90 ÷ 981 = 10/109, or 9.17%.

The 90% detection rate is not the chance that a positive result is right, because the large group without the condition supplies most of the positives.

Prior P(A)P(B given A)P(B given not A)P(B)Updated P(A given B)
0.010.90.090.09810.0917431193
0.10.90.090.1710.5263157895
0.50.80.20.50.8
00.90.090.090

At a 10% prior, the same test's positive result means a 52.6% chance, so the answer depends on prevalence as much as on accuracy. A prior of 0 stays 0 whatever the evidence. If the evidence can never occur, P(B) = 0 and the update is undefined.

Common mistakes

  • Typing percentages as whole numbers. Probabilities run from 0 to 1, so 25% is 0.25. Fractions such as 1/6 also work.
  • Adding chances for "at least one". Four rolls of a die don't give 4/6 for at least one six. Use the complement: 1 − (5/6)⁴ = 671/1296, about 0.518.
  • Assuming independence. Draw two cards without replacement and, after a first ace, the second is an ace with probability 3/51, not 4/52.
  • Swapping the condition. A 90% chance of a positive test given the condition is not a 90% chance of the condition given a positive test; above it was 9.17%.
  • Forgetting the overlap. P(A) + P(B) alone is correct only for mutually exclusive events.

For dice totals, coin runs and card draws, the dice, coin and card calculator works out the events directly. To count the outcomes first, use the permutation and combination calculator.

OpenStax explains probability terminology and the addition and multiplication rules. Chapter 4 of Grinstead and Snell's Introduction to Probability develops conditional probability and Bayes' formula.

Worked examples

Screening test: 1% prevalence, 90% sensitivity, 9% false positives

Calculate
Bayes' theorem
Prior probability P(A)
0.01
P(B | A)
0.9
P(B | not A)
0.09
P(A | B)
0.091743
P(B)
0.0981

Checked against: Gigerenzer et al. (2007) mammography example (about 1 in 10 positives has the disease); exact 0.009/0.0981 = 10/109 with exact fractions

Independent events 0.5 and 0.4

Calculate
Two events
P(A)
0.5
P(B)
0.4
How A and B relate
Independent
P(A and B)
0.2
P(A or B)
0.7
P(A | B)
0.5
P(neither A nor B)
0.3
Independent?
Yes

Checked against: P(A)P(B) = 0.2; addition rule 0.5 + 0.4 − 0.2

Mutually exclusive 0.3 and 0.45

Calculate
Two events
P(A)
0.3
P(B)
0.45
How A and B relate
Mutually exclusive
P(A and B)
0
P(A or B)
0.75
P(A | B)
0
P(exactly one of A, B)
0.75
Independent?
No

Checked against: Definition: P(A ∩ B) = 0; union is the plain sum

Known joint probability

Calculate
Two events
P(A)
0.6
P(B)
0.5
How A and B relate
I know P(A and B)
P(A and B)
0.4
P(A or B)
0.7
P(A | B)
0.8
P(B | A)
0.666667
P(neither A nor B)
0.3
P(exactly one of A, B)
0.3
Independent?
No

Checked against: Hand calculation with exact fractions: 0.4/0.5, 0.4/0.6 = 2/3, 1 − 0.7

Questions

How do you calculate the probability of A or B?

Add the two probabilities and subtract the overlap: P(A or B) = P(A) + P(B) − P(A and B). For independent events with P(A) = 0.5 and P(B) = 0.4, the overlap is 0.5 × 0.4 = 0.2, so P(A or B) = 0.7. For mutually exclusive events the overlap is 0, so the probabilities simply add: 0.3 + 0.45 = 0.75.

What is the difference between independent and mutually exclusive events?

Independent events don't affect each other's chances, so P(A and B) = P(A) × P(B). Mutually exclusive events can't happen together, so P(A and B) = 0. Two events with non-zero probabilities can't be both: if A rules out B, knowing A happened changes the chance of B to 0. Two coin flips are independent; heads and tails on one flip are mutually exclusive.

Why does a positive result on an accurate test often mean you probably don't have the condition?

Because false positives from the large healthy group can outnumber true positives from the small affected group. With 1% prevalence, 90% sensitivity and 9% false positives, only 9.17% of positives are true. At 10% prevalence the same test gives 0.09 / (0.09 + 0.081) = 52.6%. This probability is the test's positive predictive value, and it depends on prevalence as much as on accuracy.

How do you calculate the probability of at least one event happening?

Subtract the chance that it never happens from 1: P(at least one) = 1 − (1 − p)ⁿ for n independent tries with probability p each. The chance of at least one six in 4 rolls of a die is 1 − (5/6)⁴ = 671/1296, about 0.5177, just above even odds. With p = 0.01 you need 69 tries before the chance passes 50%.

About this calculator

P(A∣B)=P(B∣A) P(A)P(B∣A)P(A)+P(B∣Aˉ)P(Aˉ),P(A∪B)=P(A)+P(B)−P(A∩B)P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B \mid A)P(A) + P(B \mid \bar A)P(\bar A)},\qquad P(A \cup B) = P(A) + P(B) - P(A \cap B)

Sources

  1. Grinstead & Snell, Introduction to Probability (AMS), §4.1 Discrete conditional probability and Bayes' formula
  2. Gigerenzer et al. (2007). Helping doctors and patients make sense of health statistics. Psychological Science in the Public Interest 8(2), 53–96

Checked against references

This calculator includes 6 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.

Put this calculator on your site

Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.

Height
Preview the embed

Keep the credit line. It is the only condition, and it is what keeps these calculators free.