Codecademy Logo

Rules of Probability

Union

The union of two sets encompasses any element that exists in either one or both of them. We can represent this visually as a venn diagram as shown. Union is often represented as:

(A or B)(A\ or\ B)
A Venn diagram that shows two overlapping circles, one that represents event A and one that represents event B. Both of these circles are shaded blue.

Intersection

The intersection between two sets encompasses any element that exists in BOTH sets and is often written out as:

(A and B)(A\ and\ B)
A Venn diagram that shows two overlapping circles, one that represents event A and one that represents event B. Only the overlap of the two circles is shaded.

Addition Rule

If there are two events, A and B, the addition rule states that the probability of event A or B occurring is the sum of the probability of each event minus the probability of the intersection:

P(A or B)=P(A)+P(B)P(A and B)P(A\ or\ B) = P(A) + P(B) - P(A\ and\ B)

If the events are mutually exclusive, this formula simplifies to:

P(A or B)=P(A)+P(B)P(A\ or\ B) = P(A) + P(B)
This gif shows three sequential images of a Venn diagram that outline the formula for P(A or B). In the Venn Diagram, there are two overlapping circles: one that corresponds to event A and one that corresponds to event B. In the first image, the event A circle is shaded blue and P(A) is added to the formula. In the second image, the event B circle is shaded red and the formula now shows P(A) + P(B). In the final image, the overlap of event A and event B is shaded green and the formula now shows P(A) + P(B) - P(A and B).

Multiplication Rule

The multiplication rule is used to find the probability of two events, A and B, happening simultaneously. The general formula is:

P(A and B)=P(A)P(BA)P(A \text{ and } B) = P(A) \cdot P(B \mid A)

For independent events, this formula simplifies to:

P(A and B)=P(A)P(B)P(A \text{ and } B) = P(A) \cdot P(B)

This is because the following is true for independent events:

P(BA)=P(B)P(B \mid A) = P(B)

The tree diagram shown displays an example of the multiplication rule for independent events.

This visual shows a tree diagram that outlines all possible outcomes of flipping a fair coin two times.

Complement

The complement of a set consists of all possible outcomes outside of the set.

Let’s say set A is rolling an odd number with a 6-sided die: {1, 3, 5}. The complement of this set would be rolling an even number: {2, 4, 6}.

We can write the complement of set A as AC. One key feature of complements is that a set and its complement cover the entire sample space. In this die roll example, the set of even numbers and odd numbers would cover all possible rolls: {1, 2, 3, 4, 5, 6}.

A Venn diagram that shows a circle representing event A. Everything outside of event A is shaded blue.

Independent Events

Two events are independent if the occurrence of one event does not affect the probability of the other one occurring.

Let’s say we have a bag of five marbles: three are red and two are blue. If we select two marbles out of the bag WITH replacement, the probability of selecting a blue marble second is independent of the outcome of the first event.

The diagram below outlines the independent nature of these events. Whether a red marble or a blue marble is chosen randomly first, the chance of selecting a blue marble second is always 2 in 5.

A diagram of the possible outcomes of pulling two marbles out of a bag when pulling them out with replacement.

Dependent Events

Two events are dependent if the occurrence of one event does affect the probability of the other one occurring.

Let’s say we have a bag of five marbles: three are red and two are blue. If we select two marbles out of the bag WITHOUT replacement, the probability of selecting a blue marble second depends on the outcome of the first event.

The diagram below outlines this dependency. If a red marble is randomly selected first, the chance of selecting a blue marble second is 2 in 4. Meanwhile, if a blue marble is randomly selected first, the chance of selecting a blue marble second is 1 in 4.

A diagram of the possible outcomes of pulling two marbles out of a bag when pulling them out without replacement.

Mutually Exclusive Events

Two events are considered mutually exclusive if they cannot occur at the same time. For example, consider a single coin flip: the events “tails” and “heads” are mutually exclusive because we cannot get both tails and heads on a single flip.

We can visualize two mutually exclusive events as a pair of non-overlapping circles. They do not overlap because there is no outcome for one event that is also in the sample space for the other.

A Venn diagram that shows two non-overlapping circles, one that represents event A and one that represents event B. Nothing is shaded in the Venn diagram.

Conditional Probability

Conditional probability is the probability of one event occurring, given that another one has already occurred. We can represent this with the following notation:

Probability of event A occurring given event B has occurredP(AB)\begin{aligned} \text{Probability of event A occurring given event B has occurred} \\ P(A \mid B) \\ \end{aligned}

For independent events, the following is true for events A and B:

P(AB)=P(A)andP(BA)=P(B)\begin{aligned} P(A \mid B) = P(A) \\ \text{and} \\ P(B \mid A) = P(B) \\ \end{aligned}

Bayes’ Theorem

Bayes’ theorem is a useful tool to find the probability of an event based on prior knowledge. The formula for Bayes’ theorem is:

P(BA)=P(AB)P(B)P(A)P(B \mid A) = \frac{P(A \mid B) \cdot P(B)}{P(A)}

Learn More on Codecademy