Conditional Probability Calculator

Calculate P(A|B) — the probability of A given B — from probabilities or frequency counts.

P| Conditional Probability Calculator
P(A∩B) — Joint Probability (%)
P(B) — Marginal Probability of B (%)

P| What is Conditional Probability?

Conditional probability P(A|B) is the probability that event A occurs given that event B has already occurred. The vertical bar “|” is read as “given.” It restricts the sample space to only those outcomes where B is true, then measures the fraction of those where A is also true. The formula is: P(A|B) = P(A∩B) ÷ P(B), where P(A∩B) is the joint probability (both A and B occur) and P(B) is the marginal probability (B occurs regardless of A).

A critical warning: P(A|B) ≠ P(B|A) in general. This confusion — called the base rate fallacy or transposing the conditional — is extremely common. “The probability of a fire alarm ringing given there is a fire” is not the same as “the probability of a fire given the alarm is ringing.” A very sensitive alarm might ring for any smoke, so P(alarm | fire) = 95% but P(fire | alarm) might be only 3% in a building with many false alarms. Bayes’ theorem provides the rigorous way to go from one to the other.

Conditional probability is the foundation of Bayesian reasoning — the framework for updating beliefs in light of new evidence. Starting from a prior probability P(A), observing evidence B, and computing a posterior P(A|B) is the essence of rational belief update. This process appears everywhere: medical diagnosis (what is P(disease | symptoms)?), spam filtering (P(spam | keywords)), weather forecasting (P(rain | pressure, humidity)), and machine learning classifiers.

The 2×2 contingency table is the most natural way to compute conditional probability from real data. Rows represent one event (A, ¬A), columns represent another (B, ¬B), and cells hold observed counts. From the table, P(A|B) = count(A∩B) ÷ count(B) — the proportion of “B column” observations that also have A. This calculator supports both the formula-based approach (when you know the probabilities directly) and the frequency-based approach (when you have raw data).

📐 Formulas

P(A|B) = P(A∩B) ÷ P(B)
P(A∩B) = joint probability (both A and B occur)
P(B) = marginal probability of B (P(B) > 0)
Check: P(A|B) + P(¬A|B) = 1 (100%)
Example: P(rain∩cloudy) = 0.30, P(cloudy) = 0.40 → P(rain|cloudy) = 0.30/0.40 = 75%
Bayes’ Theorem: P(A|B) = P(B|A) × P(A) ÷ P(B)
P(A) = prior probability  ·  P(A|B) = posterior probability
P(B) = P(B|A)×P(A) + P(B|¬A)×P(¬A) [law of total probability]
Example: Disease prevalence 1%, test sensitivity 99%, specificity 95%. P(disease|positive) = (0.99×0.01) / (0.99×0.01 + 0.05×0.99) ≈ 16.7%

📖 How to Use This Calculator

Direct Input Mode

1
Enter P(A∩B) as a percentage — the probability both events occur (must be ≤ P(B)).
2
Enter P(B) as a percentage — the probability of the conditioning event (must be > 0).
3
Click Calculate to see P(A|B), P(¬A|B), joint probability, and the verification that P(A|B) + P(¬A|B) = 100%.

Contingency Table Mode

1
Enter the four cell counts: (A∩B), (¬A∩B), (A∩¬B), (¬A∩¬B) from your frequency data.
2
Click Calculate to see P(A|B) and P(B|A) — both conditional directions — plus the joint and marginal probabilities from the table.

💡 Example Calculations

Example 1 — Weather: Rain Given Clouds

P(rain ∩ cloudy) = 30%, P(cloudy) = 40%

1
P(rain | cloudy) = 0.30 / 0.40 = 0.75
2
P(¬rain | cloudy) = 1 − 0.75 = 0.25. Check: 75% + 25% = 100% ✓
P(rain | cloudy) = 75%. On cloudy days, it rains 75% of the time.
Try this example →

Example 2 — Medical Test (Contingency Table)

1,000 patients: 50 sick & positive, 10 sick & negative, 150 healthy & positive, 790 healthy & negative

1
P(sick | positive) = 50 / (50 + 150) = 50/200 = 25%
2
P(positive | sick) = 50 / (50 + 10) = 50/60 ≈ 83.3%
P(sick | positive) = 25% ≠ P(positive | sick) = 83.3%. Base rate matters!
Try this example →

Example 3 — Cards: Ace Given Red Card

P(Ace ∩ Red) = 2/52, P(Red) = 26/52

1
P(Ace | Red) = (2/52) ÷ (26/52) = 2/26 = 1/13 ≈ 7.69%
2
Note: same as unconditional P(Ace) = 4/52 = 1/13. Ace and Red card color are independent!
P(Ace | Red) = 7.69% = P(Ace). Knowing the card is red gives no info about whether it’s an ace.
Try this example →

Example 4 — Bayes’ Theorem: Spam Filter

P(spam) = 20%, P(contains “free” | spam) = 60%, P(contains “free” | not spam) = 5%

1
P(“free”) = 0.60×0.20 + 0.05×0.80 = 0.12 + 0.04 = 0.16
2
P(spam | “free”) = (0.60×0.20) / 0.16 = 0.12 / 0.16 = 75%
P(spam | contains “free”) = 75%. Seeing the word “free” triples the spam probability from 20% to 75%.
Try this example →

Frequently Asked Questions

What is conditional probability?
Conditional probability P(A|B) is the probability that event A occurs given that event B has already occurred. It is calculated as P(A|B) = P(A∩B) / P(B), where P(A∩B) is the probability both events occur together (joint probability) and P(B) is the probability of the condition (marginal probability). It measures how likely A is in the restricted sample space where B is true.
What is the formula for conditional probability?
P(A|B) = P(A∩B) / P(B). This requires P(B) > 0 (you cannot condition on an impossible event). Rearranging gives the multiplication rule: P(A∩B) = P(A|B) × P(B). Example: P(rain ∩ cloudy) = 0.30, P(cloudy) = 0.40 → P(rain | cloudy) = 0.30/0.40 = 75%.
What is the difference between P(A|B) and P(B|A)?
P(A|B) and P(B|A) are generally different. P(A|B) = P(A∩B)/P(B); P(B|A) = P(A∩B)/P(A). Example: P(cancer | positive test) ≈ 9% (rare disease, many false positives), but P(positive test | cancer) might be 95% (test is sensitive). Bayes' theorem links them: P(A|B) = P(B|A)×P(A)/P(B).
What is Bayes' theorem?
Bayes' theorem states: P(A|B) = P(B|A) × P(A) / P(B). It lets you update the probability of A after observing B. P(A) is the prior probability; P(A|B) is the posterior. Example: P(disease) = 0.01 (prior), P(positive test | disease) = 0.95, P(positive test | no disease) = 0.05. P(disease | positive test) = (0.95×0.01) / (0.95×0.01 + 0.05×0.99) ≈ 16.1%.
How do you calculate conditional probability from a contingency table?
In a 2×2 table with cells: A∩B = a, ¬A∩B = b, A∩¬B = c, ¬A∩¬B = d: P(A|B) = a/(a+b) (of the B column, what fraction is A?); P(B|A) = a/(a+c) (of the A column, what fraction is B?). Row and column totals give marginal probabilities. The total of all cells = n (total observations).
What is the multiplication rule for probability?
The multiplication rule states: P(A∩B) = P(A|B) × P(B) = P(B|A) × P(A). It gives the probability of both events occurring together. For independent events, P(A|B) = P(A), simplifying to P(A∩B) = P(A) × P(B). Example: drawing two aces without replacement: P(A₁∩A₂) = P(A₂|A₁) × P(A₁) = (3/51) × (4/52) ≈ 0.45%.
What does it mean for two events to be independent?
Events A and B are independent if P(A|B) = P(A) — knowing B occurred gives no information about A. Equivalently: P(A∩B) = P(A) × P(B). If two fair dice are rolled, the result of die 1 is independent of die 2. But if a card is drawn and not replaced, the second draw depends on the first (dependent events).
What is base rate neglect?
Base rate neglect occurs when people ignore the prior probability P(B) and focus only on P(A|B). Classic example: a test for a rare disease (prevalence 0.1%) has 99% sensitivity and 99% specificity. Most people say P(disease | positive) ≈ 99%, but the correct answer is about 9%: most positives are false positives because the disease is so rare. Always apply Bayes' theorem when evaluating test results.
How is conditional probability used in machine learning?
Conditional probability is fundamental to machine learning: Naive Bayes classifiers use P(class | features) ∝ P(features | class) × P(class). Decision trees split on features that maximize information gain (related to conditional entropy). Logistic regression models P(Y=1 | X). Hidden Markov Models use transition probabilities P(state_t | state_{t-1}). Almost every probabilistic model in ML is built on conditional probability.
What is the law of total probability?
If B₁, B₂, …, Bₙ are mutually exclusive and exhaustive events (they partition the sample space), then P(A) = Σ P(A|Bᵢ) × P(Bᵢ). This lets you compute an overall probability by conditioning on each partition. Example: P(disease) = P(disease|positive)×P(positive) + P(disease|negative)×P(negative). The law of total probability is the denominator in Bayes' theorem.