Law of Total Probability Calculator

StatisticsLast updated: August 22, 2026

The law of total probability is the route to take when the probability of an event cannot be found directly: the sample space is split into mutually exclusive, exhaustive branches A₁, A₂, …, Aₙ, and the probability is computed as the sum P(B) = ΣP(B|Aᵢ)·P(Aᵢ). The overall defect rate of a factory is the sum of the defect rates of its lines weighted by their share of production; the average resolution rate of a call center is the sum of the shift resolution rates weighted by the share of each shift.

This calculator works from one branch per line: the prior probability of the branch P(Aᵢ) and the conditional probability inside that branch P(B|Aᵢ). The output gives not only P(B) but also how much each branch adds to the total, the share each one carries, and the posterior probabilities P(Aᵢ|B) obtained from Bayes' theorem. That way the question "given that B happened, which branch did it most likely come from" is answered on the same screen.

Each line must contain two numbers: first the probability of the branch P(Aᵢ), then the conditional probability inside that branch P(B|Aᵢ). You can name a branch by writing 'Label:' at the start of the line.
If percentage is selected, both numbers on a line are divided by 100 to turn them into probabilities.
Used in the result labels. If left empty, B is used.

The Law of Total Probability

Total probability:   P(B) = Σᵢ P(B|Aᵢ) · P(Aᵢ)
Partition:           Aᵢ ∩ Aⱼ = ∅ (i ≠ j)  and  Σᵢ P(Aᵢ) = 1
Two-branch case:     P(B) = P(B|A)·P(A) + P(B|Aʹ)·P(Aʹ)
Branch contribution: P(Aᵢ ∩ B) = P(Aᵢ) · P(B|Aᵢ)
Posterior (Bayes):   P(Aᵢ|B) = P(B|Aᵢ)·P(Aᵢ) / P(B)
Check:               Σᵢ P(Aᵢ|B) = 1
Bounds:              min P(B|Aᵢ) ≤ P(B) ≤ max P(B|Aᵢ)

The rule amounts to adding up the products along the branches of a probability tree. Once P(B) has been computed as the denominator, Bayes' theorem can be applied directly with the same numbers, which is why this calculator reports the posterior probabilities alongside it.

How to Calculate

  1. Split the sample space into mutually exclusive branches: production lines, shifts, customer segments, weather scenarios, and so on.
  2. Write one branch per line: first the probability of the branch P(Aᵢ), then a semicolon and the conditional probability inside that branch P(B|Aᵢ).
  3. If you like, add a label such as 'Factory A:' at the start of a line; that name is used in the table and the charts.
  4. Choose whether you entered the probabilities as decimals or percentages, and make sure the branch probabilities add up to 1 (or 100).
  5. Compare the P(B) result with the range of the conditional probabilities; the result must always fall between the smallest and the largest conditional.
  6. Read the posterior P(Aᵢ|B) column in the table: it shows which branch becomes more likely to be responsible once the event has occurred.

Worked Examples

Defective items from three factories

Half of the output comes from factory A, 30% from factory B, and 20% from factory C, with defect rates of 2%, 3%, and 5% respectively. The total probability of a defect is P(B) = 0.50×0.02 + 0.30×0.03 + 0.20×0.05 = 0.010 + 0.009 + 0.010 = 0.029, that is 2.90%. A randomly picked defective item comes from A with probability 34.48%, from B with 31.03%, and from C with 34.48%: factory C, which has the smallest share, carries the same responsibility as A thanks to its high defect rate.

P(Kusurlu) — total probability: 2.90% · P(not Kusurlu): 97.10% · Number of branches: 3

Error rate by shift (percentage input)

45% of the transactions are handled on the morning shift, 35% at midday, and 20% at night, with error rates of 1.5%, 2.5%, and 4% respectively. The total probability of an error is 2.35%. The probability that a faulty transaction came from the night shift rises to 34.04%, even though the night shift handles only 20% of the transactions.

P(Hatalı işlem) — total probability: 2.35% · P(not Hatalı işlem): 97.65% · Number of branches: 3

A two-branch weather scenario

30% of the days are rainy; the probability of a delay is 60% on rainy days and 10% on dry ones. The total probability of a delay is 0.30×0.60 + 0.70×0.10 = 0.18 + 0.07 = 0.25, that is 25%. When a delay does occur, the probability that the day was rainy rises to 72%; the prior probability of 30% has more than doubled.

P(Gecikme) — total probability: 25.00% · P(not Gecikme): 75.00% · Number of branches: 2

Frequently Asked Questions

When is the law of total probability used?
It is used whenever the probability of an event is unknown but its probabilities under different conditions are known. The overall defect rate may be unknown, for instance, yet if the defect rate and the production share of every line are known, the rule applies directly. It is also the standard way of computing the denominator of Bayes' theorem.
What conditions must the branches satisfy?
Two conditions: the branches must be mutually exclusive (an observation can belong to only one branch) and together they must cover the whole sample space, meaning the P(Aᵢ) values add up to 1. The calculator checks the second condition and reports an error if the sum departs from 1; satisfying the first one depends on setting the problem up correctly.
Why is P(B) not the simple average of the conditional probabilities?
Because the branches carry different shares: a line with a 2% defect rate that makes half the output can produce more defective items than a line with a 5% defect rate that makes 20% of it. The total probability is the average of the conditional probabilities weighted by those shares. It equals the simple average only when all the shares are equal.
What does the posterior probability P(Aᵢ|B) tell you?
It tells you how likely it is that the event came from a given branch once it has occurred; it reverses the direction of the reasoning. With a defective item in hand, it answers the question 'which factory did this come from', and it is obtained from Bayes' theorem. The posterior probabilities also add up to 1, which the calculator displays as a check line.
How can a branch with a small share carry a large responsibility?
By having a high enough conditional probability. A factory that makes only 20% of the output but has a 5% defect rate produces just as many defective items as one that takes a 50% share with a 2% defect rate. The contribution column lets you make exactly this comparison and shows where improvement efforts should be directed.
How do I do the same calculation in Excel or R?
In Excel, put P(Aᵢ) in one column and P(B|Aᵢ) in another; the formula =SUMPRODUCT(A2:A4, B2:B4) gives the total probability, and for the posteriors you divide each row's product by that total. In R, sum(pA * pBA) and (pA * pBA) / sum(pA * pBA) are enough. This calculator performs the same computation and charts the contribution shares as well.
Does Bayes' theorem change when there are more than two branches?
The structure of the formula stays the same; only the denominator grows: P(Aᵢ|B) = P(B|Aᵢ)·P(Aᵢ) / ΣⱼP(B|Aⱼ)·P(Aⱼ). That denominator is the law of total probability itself. In problems with many branches, therefore, P(B) is computed first and then each branch's joint probability is divided by it.