Conditional Probability Calculator
Find the probability of one event given that another has occurred. Choose P(A|B) or P(B|A), then calculate it from a joint probability, from a 2 by 2 table of counts, by reversing a known conditional probability, or for two draws without replacement. Every result shows its steps.
What this conditional probability calculator does
Conditional probability answers a narrower question than ordinary probability. Instead of asking how likely A is among all outcomes, it asks how likely A is once you know B has happened. The calculator returns that value as a decimal and a percentage, shows the formula with your numbers substituted, and explains the answer in plain language.
Short answer: P(A|B) = P(A and B) / P(B), provided P(B) is greater than 0. If P(A and B) = 0.15 and P(B) = 0.4, then P(A|B) = 0.375, or 37.5%. Among the outcomes where B occurs, A also occurs in 37.5% of them.
The first choice on the calculator is the direction. Probability of A given B treats B as the condition and divides by P(B). Probability of B given A treats A as the condition and divides by P(A). A line under the menu states which event is the condition and which probability is returned, so you can see at a glance what the answer means. For the general case with a prior and new evidence, the Bayes' Theorem Calculator goes further, and the Joint Probability Calculator covers the numerator on its own.
Inputs and what you need to enter
What you must enter depends on the direction you choose and on what you know. The terms below are used throughout the page.
- Event A and event B
- Any two outcomes or sets of outcomes of the same experiment, such as "the card is a heart" and "the card is red".
- Conditioning event
- The event you are told has occurred, the one after the vertical bar. In P(A|B) it is B. Its probability is the denominator.
- Joint probability, P(A and B)
- The probability that both events occur, the event intersection, often written with an intersection sign in textbooks. It is never larger than either single-event probability.
- Marginal probability, P(A) or P(B)
- The probability of one event on its own, ignoring the other.
- Event complement, not A
- The event that A does not occur. P(not A) = 1 − P(A).
- Restricted sample space
- The outcomes left once the conditioning event is known to have occurred. Conditional probability is an ordinary probability measured inside this smaller space.
In the joint-probability mode, P(A|B) needs two numbers, P(A and B) and P(B), and P(B|A) needs P(A and B) and P(A). Entering the other single-event probability as well is optional, but it lets the calculator check that your values are consistent and report the reverse conditional probability and whether A and B are independent. Probabilities can be entered as decimals from 0 to 1 or as percentages; switching the setting converts the values you have already typed.
P(A) and P(B) on their own are generally not enough. Two events with the same single-event probabilities can overlap a lot or not at all, and the overlap is exactly what the numerator measures. Extra information can fill the gap: if you know the events are independent, then P(A|B) = P(A); if you know the reverse conditional probability and a prior, Bayes' theorem supplies the answer; and if the events are mutually exclusive, the joint probability is 0.
The conditional probability formula and notation
Written out, the definition is P(A|B) = P(A and B) / P(B). The vertical bar means "given", so P(A|B) is read "the probability of A given B". The numerator is the probability that both events occur. The denominator is P(B) because, once B is known to have occurred, only outcomes inside B are possible; dividing by P(B) rescales that smaller space so that its total probability is 1.
- Conditional probability: P(A|B) = P(A and B) / P(B), for P(B) > 0
- The other direction: P(B|A) = P(A and B) / P(A), for P(A) > 0
- Multiplication rule: P(A and B) = P(A|B) × P(B) = P(B|A) × P(A)
- Bayes' theorem: P(A|B) = P(B|A) × P(A) / P(B)
- Law of total probability: P(B) = P(B|A) × P(A) + P(B|not A) × P(not A)
- Complement rule: P(not A) = 1 − P(A), and P(not A|B) = 1 − P(A|B)
- Independence: P(A and B) = P(A) × P(B), equivalently P(A|B) = P(A) when P(B) > 0
- From counts: P(A|B) = count(A and B) / count(B)
It is easy to mix up "A given B" with "A and B". P(A and B) measures both events against all outcomes, while P(A|B) measures A against the outcomes where B occurs only. Since P(B) is at most 1, P(A|B) is never smaller than P(A and B).
How to read the step-by-step result
Each result opens with the answer as a decimal and a percentage, followed by a one-sentence interpretation. The table lists the related quantities, and the steps show the selected formula, your numbers substituted into it, and the division. The probability tree and the meter below the steps show the same result visually. The decimal places menu controls only how many digits are displayed; the arithmetic is always carried out at full precision, and a value that is not exactly 0 or 1 is never displayed as exactly 0 or 1.
Worked example: joint probability and the conditioning event
Suppose P(A and B) = 0.15, P(A) = 0.3 and P(B) = 0.4 (illustrative figures). Given B, P(A|B) = 0.15 / 0.4 = 0.375. Given A, P(B|A) = 0.15 / 0.3 = 0.5. The two answers differ because the denominators differ. If A and B were independent, the joint probability would be 0.3 × 0.4 = 0.12; the actual 0.15 is higher, so the events occur together more often than independence predicts. Choose the first mode and press Fill with an example to load these values.
Conditional probability from a two-way table
When data come as counts, conditional probability becomes a ratio of counts: the number of outcomes where both events occur divided by the total number of outcomes in the group you are given. Because each cell count divided by the group total is a relative frequency within that group, the result is also called a conditional relative frequency.
Which total to use depends on the condition. In the calculator's layout, event A is in the rows and event B in the columns, so P(A|B) divides by the B column total and P(B|A) divides by the A row total. The grand total is generally not the denominator for a conditional probability. Dividing the both-events count by the grand total gives the joint probability instead.
Worked example: a 2 by 2 table
Of 100 students, 45 attended a revision session and passed, 5 attended and did not pass, 30 did not attend and passed, and 20 did not attend and did not pass (invented figures for illustration).
| Attended (B) | Did not attend | Row total | |
|---|---|---|---|
| Passed (A) | 45 | 30 | 75 |
| Did not pass | 5 | 20 | 25 |
| Column total | 50 | 50 | 100 |
Given that a student attended, 45 of the 50 attendees passed, so P(passed | attended) = 45 / 50 = 0.9. Given that a student passed, 45 of the 75 who passed attended, so P(attended | passed) = 45 / 75 = 0.6. The grand total of 100 is not used: 45 / 100 = 0.45 is the joint probability of attending and passing.
Reversing a conditional probability with Bayes' theorem
P(A|B) and P(B|A) answer different questions and are usually different numbers. To turn one into the other you need the base rates. Bayes' theorem states P(A|B) = P(B|A) × P(A) / P(B). If P(B) is not known directly, the law of total probability builds it from the two ways B can occur: P(B) = P(B|A) × P(A) + P(B|not A) × P(not A). This calculator keeps that method in its own mode so the basic two-input calculation stays simple.
Worked example: reversing the condition
Suppose P(B|A) = 0.9, P(A) = 0.01 and P(B|not A) = 0.05. Then P(A and B) = 0.9 × 0.01 = 0.009 and P(B) = 0.009 + 0.05 × 0.99 = 0.0585. So P(A|B) = 0.009 / 0.0585, which is about 0.1538, or 15.4%. Although B is very likely when A occurs (90%), A is still fairly unlikely when B occurs, because A is rare to begin with. For multi-hypothesis problems or diagnostic-test framing, use the Bayes' Theorem Calculator.
Independent, dependent and mutually exclusive events
Events A and B are independent when knowing one does not change the probability of the other. In symbols, P(A|B) = P(A) (provided P(B) > 0), which is the same as P(A and B) = P(A) × P(B). Conditioning does not always change a probability. On a fair die, let A be "even" and B be "4 or less". Then P(A) = 1/2 and P(A|B) = (2/6) / (4/6) = 1/2, so the two events are independent. Events that are not independent are dependent, and for them P(A|B) differs from P(A).
Mutually exclusive events cannot occur together, so P(A and B) = 0 and P(A|B) = 0 whenever P(B) > 0. Mutually exclusive does not mean independent. If both events have positive probability and cannot overlap, then knowing B occurred rules A out, so P(A|B) = 0 differs from P(A) and the events are dependent. The result table says when it detects independence or exclusivity.
Probability trees and sampling without replacement
A probability tree lays out sequential outcomes. Each branch carries a probability; multiplying along a path gives the joint probability of that path, and adding the joint probabilities of several paths gives the probability of the combined outcomes. Conditional probabilities sit on the second-level branches, because they describe the second step given the first.
Sampling without replacement is the classic case where an earlier step changes a later one. Take 10 items of which 4 are marked, and draw two without putting the first back.
- Two draws from 10 items, 4 marked
- First draw markedP = 4/10
- Second markedP = 3/9Both: 12/90
- Second unmarkedP = 6/9Both: 24/90
- First draw unmarkedP = 6/10
- Second markedP = 4/9Both: 24/90
- Second unmarkedP = 5/9Both: 30/90
- First draw markedP = 4/10
After a marked first draw, 9 items remain and 3 are marked, so P(second marked | first marked) = 3/9. After an unmarked first draw, 9 remain and 4 are marked, so the probability is 4/9. Both differ from the 4/10 you started with, which is why the draws are dependent. With replacement, the second draw would always have probability 4/10. The tree also lets you reverse the condition: the paths where the second draw is marked have joint probabilities 12/90 and 24/90, a total of 36/90, so P(first marked | second marked) = (12/90) / (36/90) = 1/3. For many draws at once, see the Hypergeometric Distribution Calculator.
Edge cases and input checks
The calculator stops and explains the problem, instead of showing a misleading number, when:
- a probability is below 0 or above 1 (or outside 0% to 100% in percent mode);
- the conditioning event has probability 0, which makes the division undefined;
- the joint probability is larger than the probability of the conditioning event;
- both single-event probabilities are given and the joint probability is larger than either of them, or smaller than P(A) + P(B) − 1 (the events would then have to overlap by more than the values allow, because two events cannot together cover more than 100% of outcomes);
- a table count is negative or not a whole number, or the relevant row or column total is zero;
- in the draws mode, the marked items exceed the total, there are fewer than 2 items, or the first draw you condition on cannot happen.
A zero joint probability is not an error. It gives a conditional probability of 0, but only when the denominator is positive.
Common mistakes to avoid
- Using the wrong denominator. Divide by the total of the group you are given, not by the grand total.
- Reversing A and B. P(A|B) and P(B|A) are different questions; check which event comes after the bar.
- Confusing joint and conditional probability. "Both A and B" and "A, given B" use different denominators.
- Multiplying P(A) × P(B) for dependent events. That product equals P(A and B) only for independent events; otherwise use P(A|B) × P(B).
- Adding conditionals with different conditions. P(A|B) and P(not A|B) add to 1, but P(A|B) and P(A|not B) generally do not.
Assumptions and limitations
- The calculator applies the elementary definition of conditional probability, which requires the conditioning event to have positive probability.
- The result is only as reliable as the inputs. Probabilities estimated from a small sample carry sampling error that this calculator does not quantify.
- Table mode treats the counts as the whole group of interest. Its answers describe that group; generalising to a wider population needs inference, such as a chi-square test of independence.
- The draws mode assumes every item is equally likely to be drawn and that the first item is not returned.
- This calculator provides a mathematical result from the values you enter. It is an informational and educational tool, not professional or statistical advice. For decisions that matter, consult a qualified professional.
Formula sources
The definition, multiplication rule, independence conditions, law of total probability and Bayes' theorem were checked against these independent references:
- Common Core State Standards, High School Statistics and Probability, HSS-CP.A.3 (conditional probability and independence)
- OpenStax, Introductory Statistics, 3.2 Independent and Mutually Exclusive Events and its chapter 3 formula review
- California Institute of Technology, Math 408 Mathematical Statistics, Lecture 2: Conditional Probability (law of total probability and Bayes' theorem)
- University of Maryland, STAT 400, Conditional Probability and Bayes' Theorem (conditional sample space and a draw-without-replacement example)
Frequently asked questions
What does P(A|B) mean?
P(A|B) is the conditional probability of A given B: the probability that event A occurs when we already know that event B has occurred. The vertical bar is read as "given". Knowing B shrinks the set of possible outcomes to those where B occurs, and P(A|B) is the share of that smaller set in which A also occurs.
How do I calculate conditional probability from P(A and B) and P(B)?
Divide the joint probability by the probability of the event you are given: P(A|B) = P(A and B) / P(B), provided P(B) is greater than 0. For example, if P(A and B) = 0.15 and P(B) = 0.4, then P(A|B) = 0.15 / 0.4 = 0.375, or 37.5%.
What is the difference between P(A|B) and P(B|A)?
They share the same numerator, P(A and B), but divide by different totals: P(A|B) divides by P(B) and P(B|A) divides by P(A). They are equal only when P(A) = P(B) or when the joint probability is 0 (both are then 0), so in general they differ. The chance that someone who passed attended a session is a different question from the chance that someone who attended passed.
How do I calculate conditional probability from a two-way table?
Pick the cell where both events occur and divide it by the total of the row or column for the event you are given. If 45 of the 50 students who attended a session passed, P(passed | attended) = 45 / 50 = 0.9. The calculator's table mode does this and also shows the row, column and grand totals.
Which row or column total should I use as the denominator?
Use the total of the group named after the word "given". For P(A|B), B is the condition, so divide by the total for B, which is a column total when B runs across the top. For P(B|A), divide by the total for A, a row total in this layout. The grand total is only the denominator for an unconditional or joint probability.
How do I find P(A|B) when I know P(B|A)?
Use Bayes' theorem: P(A|B) = P(B|A) × P(A) / P(B). If you do not know P(B), build it from the law of total probability: P(B) = P(B|A) × P(A) + P(B|not A) × P(not A). With P(B|A) = 0.9, P(A) = 0.01 and P(B|not A) = 0.05, P(B) = 0.0585 and P(A|B) is about 0.1538.
How do I calculate conditional probability using a tree diagram?
Multiply the probabilities along a path to get the joint probability of that path. Then add the joint probabilities of every path that ends in the event you are given, and divide the path you want by that total. If the first split of the tree is already the condition, the probability on the branch that follows is the conditional probability.
What is conditional probability when A and B are independent?
When A and B are independent, knowing B does not change the chance of A, so P(A|B) = P(A) whenever P(B) > 0. Equivalently, P(A and B) = P(A) × P(B). For a fair die, A = "even" and B = "4 or less" are independent: P(A|B) = (2/6) / (4/6) = 1/2, which equals P(A).
What is the difference between conditional probability and joint probability?
Joint probability, P(A and B), is the chance that both events occur out of all outcomes. Conditional probability, P(A|B), is the chance of A out of only the outcomes where B occurs. They are linked by P(A and B) = P(A|B) × P(B), so the conditional probability is always at least as large as the joint probability.
Can conditional probability equal zero?
Yes. If P(A and B) = 0 and P(B) > 0, then P(A|B) = 0 / P(B) = 0, which means A never happens when B does. Mutually exclusive events with positive probabilities are an example. A zero result is valid only while the denominator is positive.
Why is P(A|B) undefined when P(B) is zero?
The formula divides by P(B), and division by zero has no value. In words, you cannot ask what happens among outcomes where B occurs if B never occurs. The calculator stops and explains this instead of showing a number. (More advanced probability theory defines conditioning on zero-probability events in special ways, but that is outside the elementary formula used here.)
How do I calculate conditional probability when sampling without replacement?
Remove the first draw from the pool before computing the second. With 10 items of which 4 are marked, the chance the second is marked after a marked first draw is 3/9, because 9 items remain and 3 of them are marked. After an unmarked first draw it is 4/9. The Two draws without replacement mode does this calculation.