Bookmarks    
nPr and nCr    
Random Number    
SD Calculator    
Sample Size    
Percent Error    
Density    
Molarity    
Molar Mass    
Ohm's Law    
Watts to Amps    
Voltage Drop    
Long Division    
Mixed Numbers    
Rounding    
Nth Root    
Exponents    
Half-Life    
Polar Form    
De Moivre    
3D Distance    
Point to Line    
Cross Product    
Determinant    
Sin Cos Tan    
Triangle Area    
Scale Factor    
Sector Area    
Ellipse Area    
Cube Volume    
Box Volume    
Sphere Volume    
Cone Volume    
Pipe Volume    
Time Duration    
Time Card    
Present Value    
Future Value    
Churn Rate    
A/B Test Calc    
SEO Traffic    
Ideal Weight    
Fat Intake    
Child Height    
Golf Handicap    
Heat Index    
Wind Chill    
Dew Point    
Download Time    
kWh to Cost    
AC Size (BTU)    
Heating Costs    
LED Savings    
Trip Gas Cost    
Tire Size    
Solar Output    
Solar Payback    
Battery Size    
Wall Area    
Gravel Needed    
Mortar Mix    
Slope Grade    
Curtain Size    
Soil Needed    
Sod Needed    
Ramp Length    
Blind Size    
Drain Slope    
Board Feet    
Heat Loss    
Furniture Fit    
Moving Boxes    
Plywood Cuts    
Shelf Sag    
   Add
Probability and random number calculators
Independent Events
Independent Events
Two Events Solver
Two Events Solver
Repeated Trials
Repeated Trials
Bayes' Theorem
Bayes' Theorem
Expected Value
Expected Value
Binomial Distribution
Binomial Distribution
nPr and nCr
nPr and nCr
Circular Permutation
Circular Permutation
With Repetition
With Repetition
Random Number
Random Number
Averages and statistics calculators
Average Calculator
Average Calculator
Mean Median Mode
Mean Median Mode
SD Calculator
SD Calculator
Quartiles & IQR
Quartiles & IQR
Frequency Table
Frequency Table
Correlation (r)
Correlation (r)
Normal Probability
Normal Probability
Z-Score Calculator
Z-Score Calculator
Confidence Interval
Confidence Interval
Sample Size
Sample Size
Mark & Recapture
Mark & Recapture
P-Value Calculator
P-Value Calculator
Percentage and ratio calculators
Percentage Calc
Percentage Calc
Percent Change
Percent Change
Percent Difference
Percent Difference
Percent Error
Percent Error
Ratio Calculator
Ratio Calculator
Discount Calculator
Discount Calculator
Sales Tax Calculator
Sales Tax Calculator
Margin Calculator
Margin Calculator
Speed calculators
Speed Calculator
Speed Calculator
Density and concentration calculators
Density
Density
Molarity
Molarity
Molar Mass
Molar Mass
Physics and electricity calculators
Ohm's Law
Ohm's Law
Watts to Amps
Watts to Amps
Resistor Colors
Resistor Colors
Voltage Drop
Voltage Drop
Unit conversion calculators
Weight Converter
Weight Converter
Shoe Size Converter
Shoe Size Converter
Integer and signed number calculators
Long Division
Long Division
LCM Calculator
LCM Calculator
GCF Calculator
GCF Calculator
Integer Calculator
Integer Calculator
Prime Factorization
Prime Factorization
Diophantine Solver
Diophantine Solver
Modulo Calculator
Modulo Calculator
Factor Calculator
Factor Calculator
Roman Numerals
Roman Numerals
Fraction, decimal and rounding calculators
Fraction Calculator
Fraction Calculator
Mixed Numbers
Mixed Numbers
Simplify Fractions
Simplify Fractions
Fraction to Decimal
Fraction to Decimal
Decimal to Fraction
Decimal to Fraction
Rounding
Rounding
Equation and inequality calculators
Linear Equation
Linear Equation
Linear Systems
Linear Systems
Quadratic Formula
Quadratic Formula
Absolute Value
Absolute Value
Quadratic Inequality
Quadratic Inequality
Polynomial calculators
Binomial Theorem
Binomial Theorem
Square root and nth root calculators
Simplify Radicals
Simplify Radicals
Nth Root
Nth Root
Exponent and logarithm calculators
Exponents
Exponents
Log Calculator
Log Calculator
Number of Digits
Number of Digits
Scientific Notation
Scientific Notation
Sci. Notation Math
Sci. Notation Math
Half-Life
Half-Life
Complex number calculators
Complex Numbers
Complex Numbers
Polar Form
Polar Form
De Moivre
De Moivre
Function and graph calculators
Slope Calculator
Slope Calculator
Linear Function
Linear Function
Direct & Inverse Variation
Direct & Inverse Variation
y = ax² Calculator
y = ax² Calculator
Distance Formula
Distance Formula
3D Distance
3D Distance
Section Formula
Section Formula
Point to Line
Point to Line
Lat/Long Distance
Lat/Long Distance
Complete the Square
Complete the Square
Circle Equation
Circle Equation
Conic Sections
Conic Sections
Polar Coordinates
Polar Coordinates
Sequence calculators
Arithmetic Sequence
Arithmetic Sequence
Geometric Sequence
Geometric Sequence
Fibonacci Sequence
Fibonacci Sequence
Recurrence Relation
Recurrence Relation
Vector calculators
Vector Calculator
Vector Calculator
Cross Product
Cross Product
Matrix calculators
Matrix Calculator
Matrix Calculator
Determinant
Determinant
Inverse Matrix
Inverse Matrix
Plane geometry calculators
Sin Cos Tan
Sin Cos Tan
Degrees ⇔ Radians
Degrees ⇔ Radians
a sin θ + b cos θ
a sin θ + b cos θ
Triangle Solver
Triangle Solver
Triangle Area
Triangle Area
Right Triangle
Right Triangle
Pythagorean Theorem
Pythagorean Theorem
Polygon Angles
Polygon Angles
Scale Factor
Scale Factor
Parallel Lines
Parallel Lines
Rectangle Area
Rectangle Area
Parallelogram Area
Parallelogram Area
Trapezoid Area
Trapezoid Area
Circle Calculator
Circle Calculator
Sector Area
Sector Area
Inscribed Angle
Inscribed Angle
Ellipse Area
Ellipse Area
Solid geometry calculators
Cube Volume
Cube Volume
Cube Surface Area
Cube Surface Area
Box Volume
Box Volume
Box Surface Area
Box Surface Area
Cylinder Volume
Cylinder Volume
Cylinder Surface
Cylinder Surface
Sphere Volume
Sphere Volume
Sphere Surface
Sphere Surface
Spherical Cap Volume
Spherical Cap Volume
Cap Surface Area
Cap Surface Area
Ellipsoid Volume
Ellipsoid Volume
Ellipsoid Surface
Ellipsoid Surface
Pyramid Volume
Pyramid Volume
Pyramid Surface
Pyramid Surface
Cone Volume
Cone Volume
Cone Surface Area
Cone Surface Area
Frustum Volume
Frustum Volume
Frustum Surface Area
Frustum Surface Area
Pipe Volume
Pipe Volume
Capsule Volume
Capsule Volume
Capsule Surface Area
Capsule Surface Area
Date and time calculators
Age Calculator
Age Calculator
Days Between Dates
Days Between Dates
Date Calculator
Date Calculator
Hours From Now
Hours From Now
Day of the Week
Day of the Week
Time Calculator
Time Calculator
Time Zone Converter
Time Zone Converter
Hours Calculator
Hours Calculator
Time Duration
Time Duration
Time Card
Time Card
Finance and economics calculators
Compound Interest
Compound Interest
Simple Interest
Simple Interest
Interest Calculator
Interest Calculator
TVM Calculator
TVM Calculator
Present Value
Present Value
Future Value
Future Value
ROI Calculator
ROI Calculator
IRR Calculator
IRR Calculator
Payback Period
Payback Period
Average Return
Average Return
GDP Calculator
GDP Calculator
Web marketing and ad metric calculators
CTR Calculator
CTR Calculator
Conversion Rate
Conversion Rate
CPC, CPM & CPA
CPC, CPM & CPA
ROAS Calculator
ROAS Calculator
Break-Even CPA
Break-Even CPA
LTV Calculator
LTV Calculator
CAC Calculator
CAC Calculator
Churn Rate
Churn Rate
A/B Test Calc
A/B Test Calc
A/B Sample Size
A/B Sample Size
SEO Traffic
SEO Traffic
Break-Even Point
Break-Even Point
Markup vs. Margin
Markup vs. Margin
CAGR Calculator
CAGR Calculator
Health and fitness calculators
BMI Calculator
BMI Calculator
Sleep Calculator
Sleep Calculator
Calorie Calculator
Calorie Calculator
BMR Calculator
BMR Calculator
TDEE Calculator
TDEE Calculator
Ideal Weight
Ideal Weight
Body Fat Calculator
Body Fat Calculator
Lean Body Mass
Lean Body Mass
Calories Burned
Calories Burned
Protein Intake
Protein Intake
Macro Calculator
Macro Calculator
Carb Calculator
Carb Calculator
Fat Intake
Fat Intake
Child Height
Child Height
Sports calculators
Golf Handicap
Golf Handicap
Pace Calculator
Pace Calculator
1RM Calculator
1RM Calculator
Target Heart Rate
Target Heart Rate
Weather calculators
Heat Index
Heat Index
Wind Chill
Wind Chill
Dew Point
Dew Point
Computer calculators
Base Converter
Base Converter
Subnet Calculator
Subnet Calculator
Download Time
Download Time
Household energy and budget calculators
Electricity Cost
Electricity Cost
kWh to Cost
kWh to Cost
Yearly kWh to Cost
Yearly kWh to Cost
AC Size (BTU)
AC Size (BTU)
AC Running Cost
AC Running Cost
Heating Costs
Heating Costs
Gas vs Electric
Gas vs Electric
LED Savings
LED Savings
Salary Calculator
Salary Calculator
Budget Calculator
Budget Calculator
Car calculators
Trip Gas Cost
Trip Gas Cost
EV Charging Cost
EV Charging Cost
EV vs Gas Cost
EV vs Gas Cost
MPG Calculator
MPG Calculator
Tire Size
Tire Size
Solar power and battery calculators
Solar Output
Solar Output
Solar Panel Count
Solar Panel Count
Solar Payback
Solar Payback
Battery Size
Battery Size
Home and DIY calculators
Tile Calculator
Tile Calculator
Stair Calculator
Stair Calculator
Concrete Volume
Concrete Volume
Wall Area
Wall Area
Wallpaper Rolls
Wallpaper Rolls
Paint Calculator
Paint Calculator
Flooring Needed
Flooring Needed
Exterior Walls
Exterior Walls
Gravel Needed
Gravel Needed
Mortar Mix
Mortar Mix
Slope Grade
Slope Grade
Lumber Cut List
Lumber Cut List
Lot Coverage/FAR
Lot Coverage/FAR
Sheet Vinyl Roll
Sheet Vinyl Roll
Insulation Needed
Insulation Needed
Curtain Size
Curtain Size
TV Size & Distance
TV Size & Distance
Soil Needed
Soil Needed
Sod Needed
Sod Needed
Block Calculator
Block Calculator
Brick Calculator
Brick Calculator
Deck Materials
Deck Materials
Ramp Length
Ramp Length
Pilot Hole Size
Pilot Hole Size
Room Ventilation
Room Ventilation
Paint Thinning
Paint Thinning
Baseboard & Trim
Baseboard & Trim
Blind Size
Blind Size
Picture Hanging
Picture Hanging
Drain Slope
Drain Slope
Screw Calculator
Screw Calculator
Board Feet
Board Feet
Fence Calculator
Fence Calculator
Wood Shrinkage
Wood Shrinkage
Caulk Calculator
Caulk Calculator
Heat Loss
Heat Loss
Furniture Fit
Furniture Fit
Moving Boxes
Moving Boxes
Storage Capacity
Storage Capacity
Plywood Cuts
Plywood Cuts
Shelf Sag
Shelf Sag

Conditional Probability and Bayes' Theorem Calculator

Choose what to calculate and enter the probabilities. The formula below is linked to the input fields, so you can also calculate by editing the numbers in the formula directly.

You can enter a probability as "0.3", "30%" or "3/10".
Result and graph
Enter the probabilities in the fields on the left and press "Calculate". The result and a figure will appear here.

What you can do on this page

  • Enter \(P(A)\) and \(P(A \cap B)\), and you get the conditional probability \(P(B \mid A) = \dfrac{P(A \cap B)}{P(A)}\) on the spot
  • In Bayes' theorem mode, you start from the probability of a cause, \(P(A)\), and the probability of a result B with and without that cause, \(P(B \mid A)\) and \(P(B \mid A')\). From these it works backward to "the probability that the cause was A, given that B happened", \(P(A \mid B)\)
  • You can follow how \(P(B)\) is built with the law of total probability, in step-by-step formulas with your numbers and in a tree diagram or area model
  • Answers are shown both as a fraction in lowest terms (the exact value), such as \(\dfrac{10}{109}\), and as a decimal and a percent
  • You can enter a probability as 0.3, 30% or 3/10. A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are included
Conditional probability works even when the two events are not independent. In fact, it is exactly the tool you need when one result changes the probability of the other.

What is this calculation used for?

Reading a test result correctly (positive does not mean almost certain)

"Positive on a 90%-accurate test" sounds like a 90% chance of having the condition. But if you assume, for example, that 1% of all people have it, the probability of really having it after a positive result (the positive predictive value) is only about 9%. The few true positives are buried among the false positives that come from the large group of people who do not have it.
This is the most famous example of Bayes' theorem, and in medicine the basic rule is to read a test result together with the prior probability. (Real probabilities differ from test to test and situation to situation, so these numbers are only an example calculation.)

Spam filters (Bayesian filters)

The classic foundation of spam detection in email apps is a Bayesian filter. From "the probability that this word appears in spam" and "the probability that it appears in normal email", it uses Bayes' theorem to work backward to "the probability that an email containing this word is spam".
Estimating "result to cause" from statistics about "cause (spam) to result (the word appears)" is a textbook application of Bayes' theorem.

Quality control in manufacturing (which line did the defect come from?)

A factory has machine X, which makes 60% of the products (2% defective), and machine Y, which makes 40% (5% defective). The probability that a defective product found in inspection came from machine X is, by Bayes' theorem, \(\dfrac{0.6 \times 0.02}{0.6 \times 0.02 + 0.4 \times 0.05} = \dfrac{3}{8}\) (37.5%).
Deciding "which line to inspect first when a defect turns up" can then be based on numbers instead of hunches.

Probabilities after a draw in raffles and card games (multiplication rule)

When you draw 2 tickets without putting them back from 10 tickets with 3 winners, the probability that both are winners is \(\dfrac{3}{10} \times \dfrac{2}{9} = \dfrac{1}{15}\). The first result changes the probability of the second (they are not independent), so this is a job for conditional probability and the multiplication rule.
Working out the odds for the rest of the deck from "the cards already showing" in poker, blackjack or other card games is exactly the same calculation.

Risk assessment in insurance and lending (breaking risk down by condition)

When setting car insurance premiums, insurers do not look at "the probability of an accident" as one number for everyone. They estimate it as a conditional probability for each condition, such as age, driving record and where you live, and reflect it in different premiums.
The idea of conditional probability, that "the probability changes once you know the condition", supports financial systems such as insurance, loan approval and credit scores.

Formulas and figures

Conditional probability
Area model
Standard notation (the usual math form)
\(P(B \mid A)\) \(=\) \(P(A \cap B)\) \(\div\) \(P(A)\)
In words (symbols replaced with words)
③ \(P(B \mid A)\): probability of B given A \(=\) ① \(P(A \cap B)\): probability that both A and B happen \(\div\) ② \(P(A)\): probability of A
The formula in words
① Take the \(P(A \cap B)\): probability that both A and B happen
② divide it by the \(P(A)\): probability of A
③ and you get the \(P(B \mid A)\): probability of B given A
Quick example
You roll a die once. Given that the number is even (probability \(\dfrac{1}{2}\)), the probability that it is 4 or more is (the even numbers that are 4 or more are 4 and 6, with probability \(\dfrac{1}{3}\))
\(P(B \mid A)\): 4 or more, given even \(=\) even and 4 or more \(\dfrac{1}{3}\) \(\div\) even \(\dfrac{1}{2}\)
\(\dfrac{1}{3} \div \dfrac{1}{2} = \dfrac{1}{3} \times 2 = \dfrac{2}{3}\)
Key idea
An ordinary probability is "the share of the whole (probability 1) taken up by B". With conditional probability, once you know that A happened, the world you are looking at shrinks from the whole to just A. So you replace the denominator 1 with \(P(A)\). Conditional probability is "the share of A taken up by B". A common mistake is to mix it up with the probability that both happen, \(P(A \cap B)\) (the joint probability). In the die example above, the probability of "even and 4 or more" out of the whole is \(\dfrac{1}{3}\), while the conditional probability out of just the even numbers is \(\dfrac{2}{3}\). The formulas look alike, but they are different probabilities because they use a different whole as the denominator. The vertical bar in \(P(B \mid A)\) is read "given", so it is read "the probability of B given A". The event to the right of the bar is the condition you already know happened. Be careful not to swap the two sides: \(P(B \mid A)\) and \(P(A \mid B)\) are usually different numbers.
Multiplication rule (probability that both happen)
Standard notation (the usual math form)
\(P(A \cap B)\) \(=\) \(P(A)\) \(\times\) \(P(B \mid A)\)
In words (symbols replaced with words)
③ \(P(A \cap B)\): probability that both A and B happen \(=\) ① \(P(A)\): probability of A \(\times\) ② \(P(B \mid A)\): probability of B given A
The formula in words
① Take the \(P(A)\): probability of A
② multiply it by the \(P(B \mid A)\): probability of B given A
③ and you get the \(P(A \cap B)\): probability that both A and B happen
Quick example
A box holds 10 raffle tickets, and 3 of them are winners. You draw 2 tickets one after the other without putting the first one back. The first is a winner with probability \(\dfrac{3}{10}\). If it is, 2 of the remaining 9 tickets are winners, so the second is also a winner with probability \(\dfrac{2}{9}\). The probability that both are winners is
\(P(A \cap B)\): both win \(=\) first wins \(\dfrac{3}{10}\) \(\times\) second wins, given the first won \(\dfrac{2}{9}\)
\(\dfrac{3}{10} \times \dfrac{2}{9} = \dfrac{6}{90} = \dfrac{1}{15}\)
Key idea
This is just the conditional probability formula with both sides multiplied by the denominator \(P(A)\), so it says the same thing in another form. Think of it as multiplying probabilities in time order: "first A happens, and then, given that, B also happens". If A and B are independent (one result does not affect the other), then \(P(B \mid A) = P(B)\), and this formula turns back into the familiar \(P(A \cap B) = P(A) \times P(B)\). In other words, "multiplying for independent events" is a special case of the multiplication rule.
Law of total probability (add up the routes to B)
Standard notation (the usual math form)
\(P(B)\) \(=\) \(P(A \cap B)\) \(+\) \(P(A' \cap B)\)
In words (symbols replaced with words)
③ \(P(B)\): probability of B \(=\) ① \(P(A \cap B)\): reaching B through A \(+\) ② \(P(A' \cap B)\): reaching B through not A
The formula in words
① Take the \(P(A \cap B)\): reaching B through A
② add the \(P(A' \cap B)\): reaching B through not A
③ and you get the \(P(B)\): probability of B
Quick example
Suppose everyone takes a certain test. Assume 1% of people have the condition (and test positive 90% of the time), and 99% do not (and wrongly test positive 9% of the time). By the multiplication rule, \(P(A \cap B) = 0.01 \times 0.9 = 0.009\) and \(P(A' \cap B) = 0.99 \times 0.09 = 0.0891\), so the probability of a positive test is
\(P(B)\): positive test \(=\) has it and positive (0.009) \(+\) does not have it but positive (0.0891)
\(0.009 + 0.0891 = 0.0981\ \ (9.81\%)\)
Key idea
There are only two routes to B: through A, or through not A (the complement \(A'\)). These two routes cannot happen at the same time (they are mutually exclusive). So simply adding the probability of each route gives \(P(B)\). Each route's probability comes from the multiplication rule: \(P(A \cap B) = P(A) \times P(B \mid A)\) and \(P(A' \cap B) = P(A') \times P(B \mid A')\). Written all together, \(P(B) = P(A)\,P(B \mid A) + P(A')\,P(B \mid A')\). In a tree diagram, this means "add up every branch that ends at B".
Bayes' theorem (work backward from a result to its cause)
Tree diagram
Standard notation (the usual math form)
\(P(A \mid B)\) \(=\) \(P(A \cap B)\) \(\div\) \(P(B)\)
In words (symbols replaced with words)
③ \(P(A \mid B)\): probability the cause is A, given B \(=\) ① \(P(A \cap B)\): reaching B through A \(\div\) ② \(P(B)\): probability of B
The formula in words
① Take the \(P(A \cap B)\): reaching B through A
② divide it by the \(P(B)\): probability of B (from the law of total probability)
③ and you get the \(P(A \mid B)\): probability the cause is A, given B
Quick example
This continues the example for the law of total probability above. When the test is positive (B), the probability that the person really has the condition (A) is
\(P(A \mid B)\): really has it, given positive \(=\) has it and positive (0.009) \(\div\) positive test (0.0981)
\(\dfrac{0.009}{0.0981} = \dfrac{90}{981} = \dfrac{10}{109} \approx 0.092\ \ (9.2\%)\)
Key idea
The form is just the conditional probability formula with the condition switched from A to B. But it is used in the opposite direction. What you know is the probability from cause to result (\(P(B \mid A)\): 90% positive if the person has the condition). What you want is the probability from result to cause (\(P(A \mid B)\): the chance that the person really has it, given a positive test). Bayes' theorem does this change of direction for you. It is often written with the denominator \(P(B)\) expanded by the law of total probability, \(P(A \mid B) = \dfrac{P(A)\,P(B \mid A)}{P(A)\,P(B \mid A) + P(A')\,P(B \mid A')}\), but the content is the same. The answer in the example, "only about 9% even after a positive result on a 90%-accurate test", is surprisingly small. This is because only 1% of people have the condition to begin with, so the few true positives are buried among the many false positives. The probability before seeing the result, \(P(A)\), is called the prior probability, and the probability after seeing the result, \(P(A \mid B)\), is called the posterior probability.
The conditional probability \(P(B \mid A)\) is "the share of B within A", found by replacing the denominator 1 (the whole) with \(P(A)\) (the given event). Bayes' theorem builds on it and works backward from the probability of "cause to result" to the probability of "result to cause". Its denominator \(P(B)\) is built with the law of total probability (adding up the routes).

Symbols and terms

Symbols

\(P(A)\) P of A The probability that event A happens. P is the first letter of "probability".
\(P(B \mid A)\) P of B given A The probability that B happens, given that A is known to have happened (the conditional probability). Some textbooks, for example in Japan, write it as \(P_{A}(B)\), with the condition as a small subscript.
\(\mid\) given The vertical bar inside \(P(\ \ )\). The event to its right is the condition (what you already know happened), and it is read "given". \(P(B \mid A)\) and \(P(A \mid B)\) mean different things.
\(A'\) A prime (complement) The event "A does not happen", called the complement of A. Also written \(A^c\) or \(\overline{A}\). It is found with \(P(A') = 1 - P(A)\).
\(\cap\) cap (intersection) The symbol for "and". \(A \cap B\) is the event "both A and B happen". In a Venn diagram it is the part where the two circles overlap.
\(P(A \cap B)\) P of A and B The probability that both A and B happen (the joint probability). It is the numerator of the conditional probability. It can never be larger than \(P(A)\), because "both happen" is part of A.

Terms

event Something that either happens or does not, such as "rolling an even number" or "testing positive". In probability, such outcomes are called events and are given names like A and B.
conditional probability The probability that an event B happens, under the condition that another event A is known to have happened. It is calculated as \(P(B \mid A) = \dfrac{P(A \cap B)}{P(A)}\). It is "the share of B in a world shrunk from the whole to just A".
multiplication rule The formula \(P(A \cap B) = P(A) \times P(B \mid A)\). It is the conditional probability formula with the denominator cleared, and finds the probability of "first A, and then B too" by multiplying in order. Also called the general multiplication rule.
law of total probability A rule that finds the probability of B by splitting it into "the route through A" and "the route through not A" and adding them. The formula is \(P(B) = P(A)\,P(B \mid A) + P(A')\,P(B \mid A')\). It is used to build the denominator of Bayes' theorem.
Bayes' theorem A rule that works backward from the probability of "cause to result" to the probability of "result to cause". The formula is \(P(A \mid B) = \dfrac{P(A \cap B)}{P(B)}\). It is named after Thomas Bayes, an 18th-century English minister, and it supports modern technology such as spam filters.
prior probability The probability of cause A, \(P(A)\), estimated before you see the result (the data). In the test example, it is "how many people have the condition in the first place".
posterior probability The probability of cause A after it is updated by seeing the result B, \(P(A \mid B)\). Bayes' theorem can be described as a rule that "updates the prior probability to the posterior probability using what you observed".
complement The opposite event, that the event does not happen. The symbol is \(A'\) and its probability is \(1 - P(A)\). In the law of total probability it covers "the route that does not go through A".
mutually exclusive Two events that cannot happen at the same time. "Reaching B through A" and "reaching B through not A" are mutually exclusive, so in the law of total probability you can simply add them.
independent When one result does not change how likely the other is. In terms of conditional probability, A and B are independent when \(P(B \mid A) = P(B)\) (knowing that A happened does not change the probability of B).
false positive A test result that says "positive" even though the person does not really have the condition. Even when the false positive rate is small, if most people do not have the condition, the number of false positives can be larger than the number of true positives.
tree diagram A diagram that lays out the possible cases like the branches of a tree. You write a probability on each branch, and multiplying along a path gives the probability of that route. It is the best diagram for following conditional probability and Bayes' theorem by eye.

Good to know before you start

Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back over the topics in this list is the fastest way forward.

Basic probability (Grade 7)
  • Knowing that when all outcomes are equally likely, probability = (number of favorable outcomes) ÷ (total number of outcomes)
  • Knowing that a probability is a number from 0 to 1, and the probabilities of all possible outcomes add up to 1
Percents and decimals (Grade 6)
  • Being able to switch between percents and decimals, such as 30% = 0.3
  • Knowing that "a share within a share", such as 0.3 of 0.5, is found by division and multiplication
Multiplying and dividing fractions (Grades 5–6)
  • Being able to divide by a fraction by multiplying by its reciprocal, as in \(\dfrac{1}{3} \div \dfrac{1}{2} = \dfrac{1}{3} \times 2 = \dfrac{2}{3}\)
  • Being able to simplify a fraction to lowest terms, as in \(\dfrac{6}{90} = \dfrac{1}{15}\)
Counting outcomes and tree diagrams (Grade 7)
  • Being able to list every possible outcome with a tree diagram or a table, without missing any
  • Knowing that if you write probabilities on the branches of a tree diagram and multiply along a path, you get the probability of that route
Sets and Venn diagrams (high school)
  • Being able to tell apart, in a diagram of two overlapping circles (a Venn diagram), "and = the overlapping part" and "or = everything inside the two circles"
  • Knowing that the probability of the complement (\(A'\) = A does not happen) is \(1 - P(A)\)

How to calculate it in Excel

Copy the whole table below and paste it into cell A1 in Excel. It works as is.
Table to find the conditional probability P(B|A)
Probability of A, P(A) 0.5
Both A and B, P(A∩B) 0.2
Conditional probability P(B|A) =B2/B1
Table to find the probability that both happen, P(A∩B) (multiplication rule)
Probability of A, P(A) 0.5
B given A, P(B|A) 0.4
Both A and B, P(A∩B) =B1*B2
Table to find the probability of B, P(B) (law of total probability)
Probability of cause A, P(A) 0.01
B given A, P(B|A) 0.9
B given not A, P(B|A') 0.09
Probability of B, P(B) =B1*B2+(1-B1)*B3
Table to find the probability of the cause, P(A|B) (Bayes' theorem)
Probability of cause A, P(A) 0.01
B given A, P(B|A) 0.9
B given not A, P(B|A') 0.09
Both A and B, P(A∩B) =B1*B2
Probability of B, P(B) =B4+(1-B1)*B3
Cause is A, given B, P(A|B) =B4/B5
After pasting, column A holds the labels and column B holds the numbers. The upper rows are your inputs, and the formulas in the lower rows calculate from them.
In a formula, "B1" and "B2" mean "use the number in that cell", "*" is multiplication and "/" is division.
The first table gives 0.2 ÷ 0.5 = 0.4, and the second gives 0.5 × 0.4 = 0.2.
The third table gives 0.01 × 0.9 + 0.99 × 0.09 = 0.0981, adding up the probability of a positive test route by route.
In the fourth table, B4 is 0.009 and B5 is 0.0981, and the last cell, B6, is 0.009 ÷ 0.0981 ≈ 0.0917 (about 9.2%).

How to calculate it in Google Sheets

Copy the whole table below and paste it into cell A1 in Google Sheets. It works as is.
Table to find the conditional probability P(B|A)
Probability of A, P(A) 0.5
Both A and B, P(A∩B) 0.2
Conditional probability P(B|A) =B2/B1
Table to find the probability that both happen, P(A∩B) (multiplication rule)
Probability of A, P(A) 0.5
B given A, P(B|A) 0.4
Both A and B, P(A∩B) =B1*B2
Table to find the probability of B, P(B) (law of total probability)
Probability of cause A, P(A) 0.01
B given A, P(B|A) 0.9
B given not A, P(B|A') 0.09
Probability of B, P(B) =B1*B2+(1-B1)*B3
Table to find the probability of the cause, P(A|B) (Bayes' theorem)
Probability of cause A, P(A) 0.01
B given A, P(B|A) 0.9
B given not A, P(B|A') 0.09
Both A and B, P(A∩B) =B1*B2
Probability of B, P(B) =B4+(1-B1)*B3
Cause is A, given B, P(A|B) =B4/B5
The same formulas as in Excel work as is. Copy the whole table and paste it into cell A1. The upper rows are your inputs and the lower rows are the calculated results.
Just replace the input numbers with your own probabilities.

How to calculate it in Python

from fractions import Fraction

# ===== Conditional probability P(B|A) = P(A∩B) ÷ P(A) =====
p_a = Fraction(1, 2)          # P(A): probability of the given event A
p_a_and_b = Fraction(1, 3)    # P(A∩B): probability that both happen
p_b_given_a = p_a_and_b / p_a
print(f"Conditional probability P(B|A): {p_b_given_a} = {float(p_b_given_a):.4f}")

# ===== Bayes' theorem (the denominator is built with the law of total probability) =====
prior = Fraction(1, 100)             # P(A): probability of cause A (prior probability)
p_b_given_a2 = Fraction(90, 100)     # P(B|A): probability of B given A
p_b_given_not_a = Fraction(9, 100)   # P(B|A'): probability of B given not A

p_joint = prior * p_b_given_a2                    # P(A∩B)
p_b = p_joint + (1 - prior) * p_b_given_not_a     # P(B) (law of total probability)
posterior = p_joint / p_b                         # P(A|B) (posterior probability)
print(f"Probability of B, P(B): {p_b} = {float(p_b):.4f}")
print(f"Probability the cause is A, P(A|B): {posterior} = {float(posterior):.4f}")
With the fractions module from the standard library, you can calculate with exact fractions and no decimal rounding errors. When you run it, the conditional probability shows as "2/3", and the Bayes' theorem example shows P(B) = 981/10000 (0.0981) and P(A|B) = 10/109 (about 0.0917). Change the probability values and run it (0.5 can be written as a fraction, such as Fraction(5, 10)).

How to write it in LaTeX and other math languages (copy and paste)

Conditional probability
P(B|A) = P(A∩B) / P(A)
P(B \mid A) = \dfrac{P(A \cap B)}{P(A)}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>P</mi><mo>(</mo><mi>B</mi><mo>&#x2223;</mo><mi>A</mi><mo>)</mo>
    <mo>=</mo>
    <mfrac>
      <mrow><mi>P</mi><mo>(</mo><mi>A</mi><mo>&#x2229;</mo><mi>B</mi><mo>)</mo></mrow>
      <mrow><mi>P</mi><mo>(</mo><mi>A</mi><mo>)</mo></mrow>
    </mfrac>
  </mrow>
</math>
P(B | A) = P(A nn B) / P(A)
pAandB/pA
pBgivenA := pAandB/pA;
p_b_given_a = p_a_and_b/p_a;
P(B|A) = P(A∩B)/P(A)
Multiplication rule (probability that both happen)
P(A∩B) = P(A) × P(B|A)
P(A \cap B) = P(A) \times P(B \mid A)
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>P</mi><mo>(</mo><mi>A</mi><mo>&#x2229;</mo><mi>B</mi><mo>)</mo>
    <mo>=</mo>
    <mi>P</mi><mo>(</mo><mi>A</mi><mo>)</mo>
    <mo>&#xD7;</mo>
    <mi>P</mi><mo>(</mo><mi>B</mi><mo>&#x2223;</mo><mi>A</mi><mo>)</mo>
  </mrow>
</math>
P(A nn B) = P(A) xx P(B | A)
pA*pBgivenA
pAandB := pA*pBgivenA;
p_a_and_b = p_a*p_b_given_a;
P(A∩B) = P(A) × P(B|A)
Law of total probability (add up the routes to B)
P(B) = P(A) × P(B|A) + P(A′) × P(B|A′)
P(B) = P(A)\,P(B \mid A) + P(A')\,P(B \mid A')
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>P</mi><mo>(</mo><mi>B</mi><mo>)</mo>
    <mo>=</mo>
    <mi>P</mi><mo>(</mo><mi>A</mi><mo>)</mo>
    <mi>P</mi><mo>(</mo><mi>B</mi><mo>&#x2223;</mo><mi>A</mi><mo>)</mo>
    <mo>+</mo>
    <mi>P</mi><mo>(</mo>
    <msup><mi>A</mi><mo>&#x2032;</mo></msup>
    <mo>)</mo>
    <mi>P</mi><mo>(</mo><mi>B</mi><mo>&#x2223;</mo>
    <msup><mi>A</mi><mo>&#x2032;</mo></msup>
    <mo>)</mo>
  </mrow>
</math>
P(B) = P(A) xx P(B | A) + P(A') xx P(B | A')
pA*pBgivenA + (1 - pA)*pBgivenNotA
pB := pA*pBgivenA + (1 - pA)*pBgivenNotA;
p_b = p_a*p_b_given_a + (1 - p_a)*p_b_given_not_a;
P(B) = P(A)P(B|A) + P(A′)P(B|A′)
Bayes' theorem (work backward from a result to its cause)
P(A|B) = P(A∩B) / P(B)
P(A \mid B) = \dfrac{P(A \cap B)}{P(B)} = \dfrac{P(A)\,P(B \mid A)}{P(A)\,P(B \mid A) + P(A')\,P(B \mid A')}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mrow>
    <mi>P</mi><mo>(</mo><mi>A</mi><mo>&#x2223;</mo><mi>B</mi><mo>)</mo>
    <mo>=</mo>
    <mfrac>
      <mrow><mi>P</mi><mo>(</mo><mi>A</mi><mo>&#x2229;</mo><mi>B</mi><mo>)</mo></mrow>
      <mrow><mi>P</mi><mo>(</mo><mi>B</mi><mo>)</mo></mrow>
    </mfrac>
  </mrow>
</math>
P(A | B) = P(A nn B) / P(B)
pA*pBgivenA/(pA*pBgivenA + (1 - pA)*pBgivenNotA)
pAgivenB := pAandB/pB;
p_a_given_b = p_a_and_b/p_b;
P(A|B) = P(A∩B)/P(B)

How to have ChatGPT  do the calculation

You are a calculation assistant for probability (conditional probability and Bayes' theorem). Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing).

The probability of cause A (the prior probability) is 1%. The probability of result B when A happens, P(B|A), is 90%. The probability of B when A does not happen, P(B|A'), is 9%.
Find each of the following:
1. The probability that both A and B happen, P(A∩B)
2. The probability of B, P(B) (using the law of total probability, and also show the breakdown by route)
3. The probability that the cause is A, given that B happened, P(A|B) (Bayes' theorem; show it both as a fraction in lowest terms and as a decimal)

In Python, use the fractions module from the standard library to calculate exactly, and show the formulas you used and the numbers from the execution result in a table.

How to Use
  1. 1
    Enter your numbers
    Type the numbers you want to calculate with into the input fields
  2. 2
    Calculate
    Press the "Calculate" button
  3. 3
    Check the result
    The result appears on the spot. The same page also explains the idea behind the calculation and the formula
  DataChef Features
Easy and Free
Unlimited conversions for free.
No technical knowledge required.
Intuitive and user-friendly operation.
No Registration Required
Available immediately after access.
Can be used without registering personal information.
Safe and Secure
Fully SSL encrypted communication.
Automatic file deletion by clicking "download".
Fast
High-speed site access
and rapid file conversion.
No Watermark
No watermark.
No attribution required.
Commercial Use Available
Free for commercial use.
No need to contact us for commercial use permission.