BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)

Conditional Probability Calculator

Calculate P(A|B) — the probability of event A given event B — from probabilities, raw counts, or a 2×2 contingency table. Switch to Bayes’ theorem mode or the independence checker. Every calculation shows the formula, substitution, and a plain-English interpretation, entirely in your browser with no signup needed.

Conditional Probability Calculator

Formula P(A|B) = P(A ∩ B) / P(B) Condition P(B) > 0
Formula P(A|B) = count(A ∩ B) / count(B) Use for Frequency data

Enter the number of outcomes. The denominator must be the total count satisfying condition B, not the total sample size.

Formula P(A|B) = a / (a + c) Where a = A∩B cell

Enter cell counts for the 2×2 table. Totals are computed automatically.

B Not B Row Total
A
Not A
Col Total
Formula P(A|B) = P(B|A) × P(A) / [P(B|A)P(A) + P(B|Ac)P(Ac)]

Enter the prior probability of A, the likelihood P(B|A), and the alternative likelihood P(B|Ac). Bayes’ theorem reverses conditional probability when P(B|A) is known but P(A|B) is needed.

Independence if P(A|B) = P(A)    or equivalently    P(A ∩ B) = P(A) × P(B)

Enter three values to check whether events A and B are independent. Two events are independent when knowing B occurred gives no information about A.

What Is Conditional Probability?

Conditional probability is the probability of event A occurring given that event B has already occurred. It is written P(A|B), read as “the probability of A given B.” The vertical bar means “given that.” Instead of asking what proportion of all outcomes fall in A, you restrict your view to outcomes where B occurred and then ask what proportion of those also fall in A.

For example: in a group of 200 students, 80 studied and passed, 20 studied and failed, 30 did not study and passed, and 70 did not study and failed. The unconditional probability of passing is 110/200 = 55%. But the conditional probability of passing given that a student studied is 80/100 = 80% — a very different number. Conditioning on B changes the relevant sample space from all 200 students to only the 100 who studied.

This idea underpins medicine (what is the probability of disease given a positive test?), law (what is the probability of guilt given the evidence?), machine learning (what is the probability of class Y given features X?), and everyday reasoning. According to Introduction to Probability, Statistics, and Random Processes (Pishro-Nik), conditional probability is one of the most fundamental and frequently misunderstood concepts in probability theory.

The Conditional Probability Formula

The conditional probability formula is P(A|B) = P(A ∩ B) / P(B), provided P(B) > 0. Every term has a precise meaning:

P(A|B) Probability of A given B — what you want to find
P(A ∩ B) Probability that both A and B occur — the numerator
P(B) Probability of the conditioning event B — the denominator
P(B) > 0 Required condition — cannot condition on an impossible event

The formula works by rescaling the joint probability P(A ∩ B) so that the conditioning event B becomes the new whole. Dividing by P(B) converts from a fraction of all outcomes to a fraction of B-outcomes. If P(B) = 0, the formula requires dividing by zero, which is undefined — this is why the condition P(B) > 0 is mandatory. See the Penn State STAT 414 introduction to conditional probability for a rigorous derivation.

Basic Formula

P(A|B) = P(A ∩ B) / P(B) Requires P(B) > 0 Read: "probability of A given B"

Count-Based Formula

P(A|B) = count(A ∩ B) / count(B) Denominator: outcomes where B is satisfied Not the total sample size

Multiplication Rule

P(A ∩ B) = P(A|B) · P(B) Also: P(A ∩ B) = P(B|A) · P(A) Both forms are equivalent

Complement Rule

P(Aᶜ|B) = 1 – P(A|B) Given B occurred, the probability A did NOT occur = 1 minus P(A|B)

How to Calculate Conditional Probability — Step by Step

To calculate P(A|B): identify the conditioning event B, find P(A ∩ B), verify P(B) > 0, then divide P(A ∩ B) by P(B). The result is the probability of A restricted to the world where B has happened.

1
Identify the conditioning event

Determine which event is B — the event you are told has occurred or that you want to condition on. This will become the new denominator. Write down P(B).

2
Find the joint probability P(A ∩ B)

Determine the probability that both A and B occur together. This can come from a two-way table, a given probability, or from counts using count(A ∩ B) / n.

3
Verify P(B) > 0

If P(B) = 0, stop. P(A|B) is undefined when the conditioning event is impossible. Conditioning on an event with zero probability has no meaning.

4
Apply the formula

Divide: P(A|B) = P(A ∩ B) / P(B). For example, if P(A ∩ B) = 0.21 and P(B) = 0.60, then P(A|B) = 0.21 / 0.60 = 0.35.

5
Interpret the result

State the answer correctly: “Given that event B occurred, the probability that event A also occurred is 35%.” Do not say simply “the probability of A is 35%” unless that unconditional probability is also 35%.

Worked Example: P(A ∩ B) = 0.21, P(B) = 0.60. Therefore P(A|B) = 0.21 / 0.60 = 0.35 = 35%. Interpretation: given that event B occurred, there is a 35% probability that event A also occurred. Use the Probabilities tab above to verify.

P(A|B) vs P(B|A): A Critical Distinction

P(A|B) and P(B|A) measure different things and are generally not equal. Treating them as interchangeable is known as the prosecutor’s fallacy or base rate fallacy and leads to serious errors in medical testing, legal reasoning, and data analysis.

QuantityWhat it meansExample interpretation
P(A|B)Probability of A given B has occurredP(disease | positive test) — positive predictive value
P(B|A)Probability of B given A has occurredP(positive test | disease) — sensitivity
P(A ∩ B)Probability both A and B occurP(disease and positive test)
P(A ∪ B)Probability A or B or both occurP(disease or positive test)
P(A)Unconditional probability of ADisease prevalence in the population

Consider the exam example above. P(Passed|Studied) = 80/100 = 80%, meaning 80% of students who studied passed. But P(Studied|Passed) = 80/110 ≈ 72.73%, meaning 72.73% of students who passed had studied. These are different questions with different answers. Bayes’ theorem is the tool for converting one into the other when you know the prior probabilities.

Conditional Probability from a Contingency Table

Given a 2×2 contingency table, P(A|B) equals the count in the A-and-B cell divided by the total count in the B column. The column total is the denominator because it represents all outcomes where B occurred.

Example: Study habits and exam results (n = 200 students)
PassedFailedRow Total
Studied80 ← a20100
Did not study3070100
Column Total110 ← a+c90200
P(Passed | Studied) = 80 / 100 = 0.80 = 80%

Among the 100 students who studied, 80 passed.

P(Studied | Passed) = 80 / 110 ≈ 0.7273 = 72.73%

Among the 110 students who passed, 80 had studied. Different question, different answer.

P(Failed | Did not study) = 70 / 100 = 0.70 = 70%

Among students who did not study, 70% failed.

P(Passed | Did not study) = 30 / 100 = 0.30 = 30%

Complement: 1 − 0.70 = 0.30.

Notice that P(Passed|Studied) ≠ P(Studied|Passed). This table directly demonstrates why the two conditional probabilities must be kept distinct. Use the 2×2 Table tab above to enter your own data and compute all eight conditional probabilities at once.

Independence and Conditional Probability

Two events A and B are independent if P(A|B) = P(A), meaning that knowing B occurred tells you nothing about whether A occurred. An equivalent condition is P(A ∩ B) = P(A) × P(B). Both formulations are exactly equivalent for events with positive probability.

Independence is not the same as mutual exclusivity. Mutually exclusive events cannot both occur, so P(A ∩ B) = 0. If both P(A) and P(B) are positive, then mutually exclusive events are not independent, because P(A ∩ B) = 0 ≠ P(A) × P(B) > 0. This is a common source of confusion among students.

ConceptDefinitionWhat it means in practice
IndependentP(A|B) = P(A)Knowing B gives no information about A
Mutually exclusiveP(A ∩ B) = 0A and B cannot occur together
DependentP(A|B) ≠ P(A)Knowing B changes the probability of A
Positively associatedP(A|B) > P(A)B makes A more likely
Negatively associatedP(A|B) < P(A)B makes A less likely

In practice, independence is tested numerically by checking whether P(A ∩ B) is close to P(A) × P(B) within a reasonable tolerance for floating-point arithmetic. Use the Independence tab above to test your own values.

Bayes’ Theorem and Conditional Probability

Bayes’ theorem reverses conditional probability: it computes P(A|B) from P(B|A) and the prior probability P(A). The formula is:

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

When B can only occur through A or Ac, the denominator expands using the law of total probability:

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

Each term has a specific name:

TermNameRole
P(A)Prior probabilityBelief about A before observing B
P(B|A)LikelihoodHow probable B is if A is true
P(B)Evidence / marginal probabilityOverall probability of observing B
P(A|B)Posterior probabilityUpdated belief about A after observing B

Medical Test Example: Why Sensitivity ≠ Positive Predictive Value

One of the most important applications of Bayes’ theorem involves interpreting medical screening tests. A positive test result does not mean the probability of disease equals the test’s sensitivity. The base rate of the disease in the population — the prior probability — changes the answer dramatically.

Scenario (illustrative only — not medical advice): A test for a rare condition has 90% sensitivity (P(Positive|Disease) = 0.90) and 95% specificity (P(Negative|No Disease) = 0.95). The disease prevalence is 1% (P(Disease) = 0.01). What is P(Disease|Positive)?
Set up the values

P(A) = P(Disease) = 0.01, P(B|A) = 0.90 (sensitivity), P(B|Ac) = 0.05 (false positive rate = 1 − specificity)

Compute P(B) using total probability

P(B) = 0.90 × 0.01 + 0.05 × 0.99 = 0.009 + 0.0495 = 0.0585

Apply Bayes’ theorem

P(Disease|Positive) = (0.90 × 0.01) / 0.0585 = 0.009 / 0.0585 ≈ 15.38%

Result: Despite a 90% sensitive test returning a positive result, there is only about a 15% probability the person actually has the disease. The low prevalence of 1% dominates the calculation. This is why screening programs for rare diseases require careful statistical interpretation. Enter these values in the Bayes tab above to verify.

Common confusion: Sensitivity P(Positive|Disease) = 90% is not the same as positive predictive value P(Disease|Positive) = 15.38%. Confusing these two quantities is a well-documented error in clinical reasoning. See NCBI’s reference on sensitivity and specificity for further context.

Conditional Probability and Sampling Without Replacement

When items are drawn from a population without replacement, the outcome of the first draw changes the composition of the remaining pool, which changes the conditional probability for the second draw.

Example: An urn contains 5 red balls and 5 blue balls (10 total). One ball is drawn without being replaced.
First draw (no conditioning)

P(Red on draw 1) = 5/10 = 0.50

Second draw given first was red

After removing one red ball, 4 red and 5 blue remain (9 total).
P(Red on draw 2 | Red on draw 1) = 4/9 ≈ 0.444

Second draw given first was blue

After removing one blue ball, 5 red and 4 blue remain (9 total).
P(Red on draw 2 | Blue on draw 1) = 5/9 ≈ 0.556

Probability tree approach

P(Red, Red) = P(Red 1) × P(Red 2 | Red 1) = 0.5 × 4/9 = 2/9 ≈ 0.222

Sampling methodSecond draw depends on first?Events are
With replacementNo — pool unchangedIndependent
Without replacementYes — pool changesDependent

Probability Trees and the Multiplication Rule

A probability tree shows sequential events. At each branch, the probability on the branch is the conditional probability of that outcome given the path taken so far. The probability of any complete path is the product of all branch probabilities along it — this is the multiplication rule.

Multiplication Rule: P(A and B) = P(A) × P(B|A)
Equivalently: P(A ∩ B) = P(B|A) × P(A) = P(A|B) × P(B)

In the urn example above: P(Red then Blue) = P(Red on 1st) × P(Blue on 2nd | Red on 1st) = (5/10) × (5/9) = 25/90 = 5/18 ≈ 27.78%. Probability trees make the structure of conditional dependence explicit and help avoid errors like dividing by the wrong denominator. You can build interactive trees at the Statistics Fundamentals probability tree tool.

The Law of Total Probability

The law of total probability says that if A1, A2, …, An form a mutually exclusive and exhaustive partition of the sample space, then P(B) = Σ P(B|Ai) × P(Ai).

P(B) = P(B|A) × P(A) + P(B|Ac) × P(Ac)
This is the denominator in Bayes’ theorem when there are exactly two mutually exclusive and exhaustive cases.

In the medical test example above: P(Positive) = P(Positive|Disease) × P(Disease) + P(Positive|No Disease) × P(No Disease) = 0.90 × 0.01 + 0.05 × 0.99 = 0.0585. This marginal probability of a positive test accounts for positives from both diseased and healthy people.

Common Mistakes in Conditional Probability

These errors appear repeatedly in student work, courtroom reasoning, and published research. Knowing them by name helps you spot them quickly.

1
Confusing P(A|B) with P(B|A)

Treating sensitivity as positive predictive value, or treating the probability of evidence given guilt as the probability of guilt given evidence. These are different quantities. Bayes’ theorem relates them.

2
Dividing by P(A) instead of P(B)

P(A|B) = P(A ∩ B) / P(B). The denominator is the probability of the event you are conditioning on (B), not the event you are computing the probability of (A).

3
Treating P(A ∩ B) as conditional probability

P(A ∩ B) and P(A|B) are different. The joint probability P(A ∩ B) is not rescaled to B’s sample space; P(A|B) is.

4
Conditioning when P(B) = 0

If P(B) = 0, P(A|B) is undefined. Do not return 0 or any other number; the formula simply does not apply.

5
Confusing independence with mutual exclusivity

Mutually exclusive events cannot both happen, so if both have positive probability, they are not independent. Independent events can both happen.

6
Ignoring the base rate

A test with 99% accuracy does not mean a positive result is 99% likely to indicate disease if the disease is rare. The prior probability (base rate) must enter through Bayes’ theorem.

7
Using the wrong denominator with counts

P(A|B) from counts = count(A ∩ B) / count(B). The denominator is the number of outcomes satisfying B, not the total sample size.

8
Rounding intermediate calculations

Round only the final answer. Rounding P(A ∩ B) or P(B) to two decimal places before dividing can change the result significantly for small probabilities.

Worked Examples

Example 1 — Basic Conditional Probability from Probabilities

Given: P(A ∩ B) = 0.15, P(B) = 0.50
Formula

P(A|B) = P(A ∩ B) / P(B)

Substitution

P(A|B) = 0.15 / 0.50 = 0.30

Answer: P(A|B) = 0.30 = 30%. Given that B occurred, the probability of A is 30%.

Example 2 — Conditional Probability from Counts

Given: 20 outcomes satisfy A ∩ B; 50 outcomes satisfy B
Formula

P(A|B) = count(A∩B) / count(B) = 20 / 50

Result

P(A|B) = 0.40 = 40%. Note: the denominator is count(B), not the total sample size.

Answer: Among the 50 outcomes where B occurred, 40% also satisfy A.

Example 3 — Card Drawing: P(Second card is a King | First card was a King)

Setup: Standard 52-card deck, drawing two cards without replacement. What is the probability the second card is a King given the first was a King?
After removing one King

3 Kings remain in a 51-card deck.

Conditional probability

P(King on 2nd | King on 1st) = 3/51 = 1/17 ≈ 5.88%

Answer: The conditional probability drops from 4/52 = 7.69% (unconditional) to 3/51 = 5.88% after one King is removed.

Example 4 — Independence Check

Given: P(A) = 0.40, P(B) = 0.50, P(A ∩ B) = 0.20
Compute P(A|B)

P(A|B) = 0.20 / 0.50 = 0.40

Compare with P(A)

P(A|B) = 0.40 = P(A). Also: P(A)×P(B) = 0.40×0.50 = 0.20 = P(A∩B). ✓

Answer: A and B are independent. Knowing B occurred does not change the probability of A.

Example 5 — Demonstrating P(A|B) ≠ P(B|A)

Given: P(A ∩ B) = 0.12, P(A) = 0.30, P(B) = 0.40
P(A|B)

P(A|B) = 0.12 / 0.40 = 0.30

P(B|A)

P(B|A) = 0.12 / 0.30 = 0.40

Answer: P(A|B) = 0.30 and P(B|A) = 0.40. These happen to equal P(A) and P(B) respectively, confirming independence, but the two conditional probabilities themselves are not equal.

Conditional Probability in Excel and Google Sheets

There is no dedicated conditional probability function in Excel or Google Sheets. The calculation uses standard formulas for division and counting. Both applications handle these calculations identically.

From Probabilities

=B2/B3 ' Where B2 = P(A ∩ B) and B3 = P(B) ' Add error checking: =IF(B3=0,"Undefined",B2/B3)

From a Contingency Table Using COUNTIFS

' Suppose column A has the B indicator (1=B, 0=Not B) ' Suppose column B has the A indicator (1=A, 0=Not A) ' Count(A ∩ B) =COUNTIFS(A2:A201,1,B2:B201,1) ' Count(B) =COUNTIF(A2:A201,1) ' P(A|B) =COUNTIFS(A2:A201,1,B2:B201,1)/COUNTIF(A2:A201,1) ' With division-by-zero protection =IFERROR(COUNTIFS(A2:A201,1,B2:B201,1)/COUNTIF(A2:A201,1),"Undefined")

Conditional Probability in Python

From Probabilities

def conditional_probability(p_a_and_b, p_b, tol=1e-12): """Compute P(A|B) = P(A ∩ B) / P(B).""" if not (0 <= p_a_and_b <= 1 and 0 <= p_b <= 1): raise ValueError("Probabilities must be between 0 and 1.") if p_b < tol: return None # P(A|B) is undefined when P(B) = 0 if p_a_and_b > p_b + tol: raise ValueError("P(A ∩ B) cannot exceed P(B).") return p_a_and_b / p_b result = conditional_probability(0.21, 0.60) print(f"P(A|B) = {result:.6f} = {result*100:.4f}%") # P(A|B) = 0.350000 = 35.0000%

From a Contingency Table with pandas

import pandas as pd # Build a 2x2 table data = {'B': [80, 30], 'Not_B': [20, 70]} df = pd.DataFrame(data, index=['A', 'Not_A']) # Conditional probabilities p_a_given_b = df.loc['A', 'B'] / df['B'].sum() p_b_given_a = df.loc['A', 'B'] / df.loc['A'].sum() print(f"P(A|B) = {p_a_given_b:.4f}") # 0.7273 print(f"P(B|A) = {p_b_given_a:.4f}") # 0.8000

Conditional Probability in R

# From probabilities conditional_prob <- function(p_a_and_b, p_b) { if (p_b == 0) stop("P(B) = 0: conditional probability undefined.") p_a_and_b / p_b } conditional_prob(0.21, 0.60) # 0.35 # From a contingency table tab <- matrix(c(80, 30, 20, 70), nrow = 2, dimnames = list(c("A","Not_A"), c("B","Not_B"))) p_table <- prop.table(tab) # cell proportions of n p_a_given_b <- tab["A","B"] / sum(tab[,"B"]) cat("P(A|B) =", round(p_a_given_b, 4)) # 0.7273

Related Probability Calculators and Guides

Conditional probability connects directly to these topics. Each tool or guide at Statistics Fundamentals extends what you can do with the concepts covered here.

Frequently Asked Questions

Conditional probability is the probability of event A occurring given that event B has already occurred. It is written P(A|B), read as “the probability of A given B.” The vertical bar means “given that.” It restricts the sample space from all outcomes to only those where B occurred, then asks what fraction of those also satisfy A.

P(A|B) means the probability of event A given that event B occurred. The vertical bar is read as “given that.” It restricts the sample space to outcomes where B is true and asks what fraction of those outcomes also satisfy A. For example, P(Passed|Studied) is the probability a student passed, looking only at students who studied.

The conditional probability formula is P(A|B) = P(A ∩ B) / P(B), provided P(B) > 0. P(A ∩ B) is the probability both events occur; P(B) is the probability of the conditioning event. If P(B) = 0, then P(A|B) is undefined — you cannot condition on an impossible event.

P(A|B) is the probability of A given B, while P(B|A) is the probability of B given A. These are generally not equal. In medical testing, P(positive|disease) is sensitivity, while P(disease|positive) is positive predictive value — two very different numbers when disease prevalence is low. Confusing them is called the base rate fallacy. Bayes’ theorem is the tool that converts one into the other using prior probabilities.

When P(B) = 0, conditional probability P(A|B) is undefined. You cannot condition on an event that cannot happen. Dividing by zero has no mathematical meaning, so the formula does not apply. This calculator displays “undefined” rather than returning 0 or any other number in this situation.

From a 2×2 contingency table, P(A|B) = (count in the A-and-B cell) / (column total for B). For example, if 80 of 100 students who studied passed, then P(Passed|Studied) = 80/100 = 0.80. The denominator is the total count for the conditioning event B, not the grand total of all observations.

Events A and B are independent if P(A|B) = P(A), meaning knowing B occurred gives no information about A. An equivalent condition is P(A ∩ B) = P(A) × P(B). Independence is not the same as mutual exclusivity. Mutually exclusive events with positive probability cannot be independent, because P(A ∩ B) = 0 ≠ P(A)×P(B) > 0.

Bayes’ theorem states P(A|B) = P(B|A) × P(A) / P(B). It reverses conditional probability, converting P(B|A) into P(A|B) using the prior probability P(A) and the marginal evidence P(B). It is fundamental to medical test interpretation, spam filtering, machine learning classifiers, and Bayesian statistics.

No. Conditional probability is still a probability, so it must fall between 0 and 1 inclusive. If your calculation produces a value outside this range, there is an input error — most commonly P(A ∩ B) exceeds P(B), which is a logical impossibility since the intersection cannot be more probable than B alone.

When items are drawn without replacement, removing one item changes the composition of the remaining pool. This makes successive draws dependent: the probability of the second draw depends on the outcome of the first. With replacement, the pool is restored after each draw so draws are typically independent. This distinction matters in card games, urn problems, and quality-control sampling.

P(A|B) from counts = count(A ∩ B) / count(B). The denominator is the number of outcomes satisfying condition B, not the total sample size. For example, if 20 of 50 items satisfying B also satisfy A, then P(A|B) = 20/50 = 0.40. This applies when outcomes are equally likely or when counts represent the appropriate frequencies.

The multiplication rule states P(A ∩ B) = P(A|B) × P(B), which also equals P(B|A) × P(A). It converts conditional probability into joint probability and is the basis of probability tree calculations. When events are independent, this simplifies to P(A ∩ B) = P(A) × P(B).

No, not when both have positive probability. Mutually exclusive events have P(A ∩ B) = 0. Independence requires P(A ∩ B) = P(A) × P(B). If both P(A) > 0 and P(B) > 0, then P(A) × P(B) > 0 ≠ 0, so mutual exclusivity and statistical independence are incompatible conditions for events with positive probability.

The law of total probability states that if A1, …, An form a mutually exclusive and exhaustive partition of the sample space, then P(B) = Σ P(B|Ai) P(Ai). For two events: P(B) = P(B|A) P(A) + P(B|Ac) P(Ac). This is how the denominator in Bayes’ theorem is computed when P(B) is not directly known.

Conditional probability is central to classification and prediction. A Naïve Bayes classifier computes P(class | features) using Bayes’ theorem with a conditional independence assumption. Logistic regression directly models P(Y=1 | X). Decision trees split on features that most change the conditional class distribution. Every supervised learning algorithm estimates some form of conditional probability.