Probability

Bayes Theorem Calculator

Use this Bayes theorem calculator to find P(A|B) from a prior probability and new evidence. Enter probabilities as decimals and get the posterior probability with a clear, step-by-step solution.

Input Type
Choose P(B) Known if the question gives P(B). Choose P(B) Unknown if you are given P(B|A) and P(B|not A) instead.
Probability of A before observing B.
Probability of B occurring when A is true.
Overall probability that B occurs.
Probability of A before observing B.
Probability of B occurring when A is true.
Probability of B occurring when A is not true.
Enter probabilities as decimals from 0 to 1. Example results are shown automatically. After changing the values, click Calculate to update the results.

How to Use the Bayes Theorem Calculator

The calculator helps you find the posterior probability, P(A|B), using Bayes’ theorem. The calculator allows you to calculate posterior probability when P(B) is known or unknown. To use the calculator, choose the option that matches the information you have and enter the required values.

For instance, if P(B) is known:

  1. Choose the P(B) Known input type option
  2. Enter the prior probability, P(A).
  3. Enter the likelihood, P(B|A).
  4. Enter the overall probability of the evidence, P(B).
  5. Click Calculate.

The calculator applies Bayes’ theorem directly and returns P(A|B), together with a clear step-by-step solution.

However, if P(B) is unknown but you know the probability of B when A is true and when A is not true:

  1. Select the P(B) unknown input type option
  2. Enter the prior probability, P(A).
  3. Enter the likelihood, P(B|A).
  4. Enter P(B|not A).
  5. Click Calculate.

The calculator first finds P(not A), then calculates P(B) using the law of total probability before applying Bayes’ theorem. It then returns the correct probability along with a clear, step-by-step solution, showing you how the probability was computed.

Note. You should enter all probabilities as decimals between 0 and 1.

Example 1: When P(B) Is Known- Using the Calculator

Suppose 30% of students at a university major in business. Among business majors, 60% take an economics course. Overall, 40% of students take the economics course. Find the probability that a student is a business major given that the student takes the economics course.

Solution

Let:

  • A = student is a business major
  • B = student takes the economics course

From the question, we know that:

  • P(A) = 0.30
  • P(B|A) = 0.60
  • P(B) = 0.40

In this case, we need to find P(A|B) when P(B) is known. To do so using the calculator:

  1. Select the P(B) known input type
  2. Enter Prior probability, P(A) = 0.30
  3. Enter Likelihood, P(B|A) = 0.60
  4. Enter Probability of evidence, P(B) = 0.40
  5. Click calculate

The calculator applies Bayes’ theorem and returns P(A|B) as 0.45. It also shows you exactly how the value was obtained, step-by-step.

Since P(A|B) = 0.45, we can conclude that the probability that the student is a business major, given that the student takes the economics course, is 0.45.

Example 2: When P(B) Is Unknown – Using the Calculator

A university estimates that 8% of students are at risk of dropping a course. An early-warning system flags 80% of students who are at risk and 12% of students who are not at risk. If a student is flagged, find the probability that the student is actually at risk of dropping the course.

Solution

Let:

  • A = student is at risk of dropping the course
  • B = student is flagged

From the question:

  • P(A) = 0.08
  • P(B|A) = 0.80
  • P(B|not A) = 0.12

As you can see, we need to find P(A|B), which requires P(B) to compute using Bayes’ theorem. However, P(B) is not given, and we need to estimate it. This calculator applies the rules of probability and computes P(A|B). To find this probability using the calculator:

  1. Choose the P(B) Unknown as the input type
  2. Enter Prior probability, P(A) = 0.08
  3. Enter Likelihood, P(B|A) = 0.80
  4. Enter Probability of B given not A, P(B|not A) = 0.12
  5. Click Calculate.

The calculator will instantly find the unknown P(B) from the entered information and proceed to give you P(A|B). In this case, P(A|B) = 0.366972. This implies the probability that the student is actually at risk of dropping the course, given that the student was flagged, is approximately 0.366972.

What Is Bayes’ Theorem?

Bayes’ theorem is a probability rule used to update the probability of an event after new information becomes available.

Suppose A is an event you are interested in and B is new evidence. You may already know the probability of A before observing B. Bayes’ theorem combines that prior probability with information about how likely B is when A occurs. The result is P(A|B), which is read as “the probability of A given B.”

In other words, Bayes’ theorem helps answer questions such as:

  • What is the probability that a student belongs to a particular group given that the student has a certain characteristic?
  • What is the probability that a condition is present given a positive test result?
  • What is the probability that an alert represents a real problem given that the system triggered a warning?

Bayes’ theorem is closely related to conditional probability. If you already know the joint probability P(A ∩ B), you may instead want to use our Conditional Probability Calculator.

Bayes’ Theorem Formula

The standard Bayes’ theorem formula is:

P(A|B) = [P(B|A) × P(A)] / P(B)

where:

  • P(A) is the prior probability of A
  • P(B|A) is the likelihood, or probability of B given A
  • P(B) is the overall probability that B occurs
  • P(A|B) is the posterior probability of A after observing B

The posterior probability is therefore the updated probability of A after taking the evidence B into account.

Prior, Likelihood, Evidence, and Posterior

The terms used in Bayes’ theorem can seem confusing at first. The following table summarizes what each one means.

TermSymbolMeaning
Prior probabilityP(A)Probability of A before observing B
LikelihoodP(BA)
EvidenceP(B)Overall probability that B occurs
Posterior probabilityP(AB)

The main result we usually want is the posterior probability.

How to Calculate Bayes’ Theorem When P(B) Is Known

When P(B) is given directly, you only need to identify the provided probabilities and apply Bayes’ theorem. Specifically, we simply use the formula: P(A|B) = [P(B|A) × P(A)] / P(B) because all the information on the right-hand side is provided.

Example 1: Calculating P(A|B) Manually, when P(B) is Known

At a university, 28% of students are engineering majors. Among engineering majors, 75% are enrolled in a programming course. Overall, 42% of students are enrolled in a programming course. If a randomly selected student is enrolled in a programming course, find the probability that the student is an engineering major.

Solution

Let:

  • A = student is an engineering major
  • B = student is enrolled in a programming course

From the question, we know that:

  • P(A) = 0.28
  • P(B|A) = 0.75
  • P(B) = 0.42

We want to find P(A|B).

Recall: P(A|B) = [P(B|A) × P(A)] / P(B)

Substituting the values gives:

P(A|B) = (0.75 × 0.28) / 0.42

= 0.21 / 0.42

= 0.5

Therefore, P(A|B) = 0.5. This implies that, given a student is enrolled in the programming course, the probability that the student is an engineering major is 0.5.

How to Use Bayes’ Theorem When P(B) Is Unknown

Some Bayes problems do not give P(B) directly. Instead, you may be given:

  • P(A)
  • P(B|A)
  • P(B|not A)

In that case, follow these steps:

  1. Find P(not A). Since A and not A are complements, P(not A) = 1 − P(A)
  2. Find P(B). Using the law of total probability, P(B) = P(B|A)P(A) + P(B|not A)P(not A). This accounts for the two ways that B can occur: when A is true and when A is not true.
  3. Apply Bayes’ Theorem. Once P(B) is known, we use Bayes’ theorem formula: P(A|B) = [P(B|A) × P(A)] / P(B)

The result, P(A|B), is the posterior probability of A after observing B.

Love memorizing formulas? You can use the following combined formula to find P(A|B) when P(B) is unknown.

P(A|B) = [P(B|A)P(A)] / [P(B|A)P(A) + P(B|not A)P(not A)]

Since P(not A) = 1 − P(A), the same formula can also be written as: P(A|B) = [P(B|A)P(A)] / [P(B|A)P(A) + P(B|not A)(1 − P(A))]

The calculator performs these intermediate calculations automatically when you select P(B) Unknown.

Example 1: Finding P(A|B) Manually when P(B) is not Given (Unknown)

A university health center screens students for a condition that affects 4% of the student population. The screening test correctly gives a positive result for 92% of students who have the condition. Among students who do not have the condition, 5% still receive a positive result. If a student tests positive, find the probability that the student actually has the condition.

Solution

Let:

  • A = student has the condition
  • B = student receives a positive result

From the question, we know that:

  • P(A) = 0.04
  • P(B|A) = 0.92
  • P(B|not A) = 0.05

To find P(A|B) by hand, follow these steps:

Step 1. Find P(not A)

Using the complement rule, P(not A) = 1- P(A)

Thus, P(not A) = 1 − 0.04

= 0.96

Step 2. Find P(B)

Using the law of total probability, P(B) = P(B|A)P(A) + P(B|not A)P(not A)

Substituting the values into the formula, we get:

P(B) = (0.92 × 0.04) + (0.05 × 0.96)

= 0.0368 + 0.048

= 0.0848

Step 3. Apply Bayes Theorem Formula

By definition, Bayes’ theorem formula is: P(A|B) = [P(B|A) × P(A)] / P(B)

Substituting the values, we have:

P(A|B) = (0.92 × 0.04) / 0.0848

= 0.0368 / 0.0848

= 0.433962

Therefore, P(A|B) = 0.433962. This implies that, given that the student received a positive result, the probability that the student actually has the condition is approximately 0.433962.

Bayes’ Theorem and Medical Test Problems

Medical screening questions are one of the most common applications of Bayes’ theorem in introductory probability courses. Instead of using only symbols such as P(A) and P(B|A), these questions often use terms such as prevalence, sensitivity, specificity, false-positive rate, and positive predictive value.

Suppose:

  • A = a person has the condition
  • not A = a person does not have the condition
  • B = the test result is positive
  • not B = the test result is negative

The medical-testing terms then correspond to the following probabilities:

Medical test termProbability notationMeaning
PrevalenceP(A)Probability that a person has the condition
SensitivityP(B|A)Probability of a positive test given that the condition is present
SpecificityP(not B|not A)Probability of a negative test given that the condition is absent
False-positive rateP(B|not A)Probability of a positive test given that the condition is absent
Positive predictive value (PPV)P(A|B)Probability of having the condition given a positive test

A common source of confusion is the difference between specificity and the false-positive rate. Specificity is P(not B|not A), while the false-positive rate is P(B|not A).

Since a positive and negative test are complementary outcomes when the condition is absent, P(B|not A) = 1 − P(not B|not A). Therefore: False-positive rate = 1 − specificity

For example, if the specificity is 0.95, P(B|not A) = 1 − 0.95 = 0.05. Hence, the false-positive rate is: P(B|not A) = 0.05. This is the value you would enter as P(B|not A) when using the P(B) Unknown option in the calculator.

Example 1: Find the Probability of Having a Condition Given a Positive Test

A university health center screens students for a condition that affects 5% of the student population. The test has a sensitivity of 0.90 and a specificity of 0.95. If a student tests positive, find the probability that the student actually has the condition.

Solution

Let:

  • A = student has the condition
  • B = student tests positive

From the question, we know that:

  • Prevalence, P(A) = 0.05
  • Sensitivity, P(B|A) = 0.90
  • Specificity, P(not B|not A) = 0.95

We want to find P(A|B), when P(B) is not given. To find this probability by hand, follow these steps:

Step 1: Find the false-positive rate

Recall. Using the complement rule, False-positive rate, P(B|not A) = 1 – specificity

P(B|not A) = 1 − 0.95

= 0.05

Step 2: Find P(not A)

Since A and not A are complements, P(not A) = 1 − P(A)

Hence, P(not A) = 1 − 0.05

= 0.95

Step 3: Find P(B)

A positive test can occur in two ways:

  • the student has the condition and tests positive;
  • the student does not have the condition and still tests positive.

Therefore, use the law of total probability, P(B) = P(B|A)P(A) + P(B|not A)P(not A)

Substituting the values into the formula, we get:

P(B) = (0.90 × 0.05) + (0.05 × 0.95)

= 0.045 + 0.0475

= 0.0925

Step 4: Apply Bayes’ Theorem

Now that P(B) is known, we use Bayes’ theorem formula.

Hence, P(A|B) = (0.90 × 0.05) / 0.0925

= 0.045 / 0.0925

= 0.486486

This implies that, given that the student tested positive, the probability that the student actually has the condition is approximately 0.486486.

Bayes’ Theorem vs. Conditional Probability

Bayes’ theorem and conditional probability are closely related. The standard conditional probability formula is: P(A|B) = P(A ∩ B) / P(B). Bayes’ theorem uses the relationship: P(A ∩ B) = P(B|A)P(A)

Substituting this into the conditional probability formula gives: P(A|B) = [P(B|A)P(A)] / P(B)

Therefore, Bayes’ theorem is particularly useful when you know P(B|A) but want to find the reverse probability P(A|B). However, if your problem already gives P(A ∩ B), use the Conditional Probability Formula.

Frequently Asked Questions

What is a Bayes theorem calculator?

This is an online tool that finds the posterior probability P(A|B) after new evidence B is observed. To use the calculator, enter the prior probability, likelihood, and either P(B) or P(B|not A), and click calculate. The calculator applies Bayes’ theorem and returns the correct probability with a step-by-step solution.

What is Bayes’ theorem used for?

Bayes’ theorem is used to update a probability when new evidence becomes available. Common applications include screening tests, classification, quality control, risk analysis, spam detection, and other problems where a prior probability is revised after observing new information.

What is Bayes’ theorem formula?

Bayes’ theorem formula is P(A|B) = [P(B|A) × P(A)] / P(B), where P(A) is the prior probability, P(B|A) is the likelihood, P(B) is the probability of the evidence, and P(A|B) is the posterior probability.

What if P(B) is not given?

If P(B) is unknown but you know P(B|A) and P(B|not A), you can calculate P(B) using the formula: P(B) = P(B|A)P(A) + P(B|not A)P(not A), where P(not A) = 1 − P(A). You can then apply Bayes’ theorem.

What is the difference between prior and posterior probability?

The prior probability, P(A), describes how likely A is before observing B, whereas the posterior probability, P(A|B), is the updated probability after B has been observed.

Is P(A|B) the same as P(B|A)?

No. P(A|B) is the probability of A given B, while P(B|A) is the probability of B given A. Bayes’ theorem provides a way to relate these two probabilities.

Can I use sensitivity and specificity with Bayes’ theorem?

Yes. Sensitivity corresponds to P(B|A). If B represents a positive test result, specificity corresponds to P(not B|not A). To obtain P(B|not A), subtract the specificity from 1.

Cite

Choose APA, MLA, Chicago, or Harvard, then copy the citation.

Mburu, J.. (2026, September 8). Bayes Theorem Calculator. StatCalc.net. Retrieved September 11, 2026, from https://statcalc.net/bayes-theorem-calculator/

Joseph Mburu

About This Calculator

Prepared by Joseph Mburu · Updated on

Joseph is an applied statistician and data analyst with over 6 years of experience helping students, researchers, and professionals solve statistics and data analysis problems. He holds a degree in Applied Statistics and a Master’s degree in Data…

We aim to keep our calculators accurate, easy to use, and helpful for learning. Always check that your inputs match the assumptions of the method you are using.