Sum and Product Rules for Counting

The sum and product rules for counting are the two basic counting tools. The sum rule says that choosing one option from m ways or n other ways, with no overlap, gives m + n choices. The product rule says that m ways followed by n ways give mn ways.

Before this lesson: Set Operations, Power Sets and Cartesian Products and Permutations and Combinations

When to add and when to multiply

A café offers 4 soups and 3 salads as starters. If you order one starter, you pick a soup or a salad, so you have 4 + 3 = 7 choices. Now suppose a meal is a starter and one of 5 main dishes. Each of the 7 starters pairs with each of the 5 mains, so there are 7 · 5 = 35 meals.

That is the whole idea. “Or” between choices that cannot happen together means add. “And then” between steps that happen one after the other means multiply. Most counting problems are a mix of the two.

A tree diagram for choosing an outfit. From a starting point, two branches lead to a red shirt and a blue shirt. From each shirt, three branches lead to jeans, khakis and shorts. The six leaves on the right list the outfits: red with jeans, red with khakis, red with shorts, blue with jeans, blue with khakis and blue with shorts.
Two shirts, each followed by three choices of pants, give 2 · 3 = 6 outfits.

The sum rule and the product rule

Sum rule. If a choice can be made from set A or from set B, and no option is in both (A and B are disjoint), then the number of choices is |A| + |B|. Here |A| means the number of elements of A.

|A \cup B| = |A| + |B| \qquad \text{if } A \cap B = \varnothing

Product rule. If a task is a sequence of k steps, and step i can be done in ni ways no matter how the earlier steps were done, then the task can be done in n1n2⋯nk ways. In set language, this counts the ordered lists in a Cartesian product.

|A_1 \times A_2 \times \cdots \times A_k| = |A_1| \cdot |A_2| \cdots |A_k|

The product rule is also called the multiplication principle or the fundamental counting principle. The key condition is “no matter how the earlier steps were done”: the number of choices at each step must stay the same, even if the choices themselves change.

How to set up a counting problem

  1. Decide what one outcome looks like, for example a 3-digit number or a meal.
  2. If outcomes come in separate types that cannot overlap, split into cases and plan to add.
  3. Within each case, build an outcome step by step and multiply the number of choices at each step.
  4. Fill the most restricted positions first, such as a first digit that cannot be 0.
  5. Add the case totals.

Sum and product rule examples

Example 1: The sum rule

A student must take one elective, either one of 5 art courses or one of 4 music courses. No course is in both lists. How many choices does the student have?

|A| = 5,\ |M| = 4

Count each list of options.

A \cap M = \varnothing

No course is in both, so the sum rule applies.

|A \cup M| = 5 + 4 = 9

Add the counts.

Answer: 9 choices.

Example 2: License plates

A license plate has 3 letters followed by 4 digits, and repeats are allowed. How many plates are possible?

26 \cdot 26 \cdot 26 = 17{,}576

Each of the 3 letter positions has 26 choices.

10 \cdot 10 \cdot 10 \cdot 10 = 10{,}000

Each of the 4 digit positions has 10 choices.

17{,}576 \cdot 10{,}000 = 175{,}760{,}000

Multiply the two parts (product rule).

Answer: 175,760,000 plates.

Example 3: Passwords of different lengths

A password has 6, 7 or 8 characters, and each character is an uppercase letter or a digit. How many passwords are possible?

26 + 10 = 36

Each character is a letter or a digit (sum rule).

36^6 = 2{,}176{,}782{,}336

Length 6: 6 positions with 36 choices each (product rule).

36^7 = 78{,}364{,}164{,}096

Length 7.

36^8 = 2{,}821{,}109{,}907{,}456

Length 8.

2{,}176{,}782{,}336 + 78{,}364{,}164{,}096 = 80{,}540{,}946{,}432

The lengths are separate cases, so add. Start with the first two.

80{,}540{,}946{,}432 + 2{,}821{,}109{,}907{,}456 = 2{,}901{,}650{,}853{,}888

Add the third case.

Answer: 2,901,650,853,888 passwords, about 2.9 trillion. Both rules appear: the sum rule for the 36 symbols and for the three lengths, and the product rule within each length.

Example 4: Numbers with no repeated digit

How many three-digit numbers (100 to 999) have three different digits?

9

The first digit can be 1 to 9, since it cannot be 0.

9

The second digit can be any of the 10 digits except the first one.

8

The third digit can be any digit except the first two.

9 \cdot 9 \cdot 8 = 81 \cdot 8 = 648

Multiply (product rule).

Answer: 648 numbers. The second step always has 9 choices, even though which 9 digits depends on the first digit. That is all the product rule needs.

Example 5: An even locker code (word problem)

A locker code is a three-digit number from 100 to 999 with no repeated digit, and it must be even. How many codes are there?

\text{last digit } 0 \text{ or last digit } 2, 4, 6, 8

The last digit controls what the first digit can be, so split into two cases.

1 \cdot 9 \cdot 8 = 72

Case 1: last digit 0. The first digit has 9 choices (1 to 9) and the middle digit has 8.

4

Case 2: choose the last digit from 2, 4, 6, 8.

8

The first digit cannot be 0 or the last digit, so it has 8 choices.

8

The middle digit cannot match the other two, so it has 8 choices.

4 \cdot 8 \cdot 8 = 256

Multiply the case 2 choices.

72 + 256 = 328

The cases do not overlap, so add.

Answer: 328 codes. Filling the first digit first would not work here: whether the last digit can be 0 depends on what came before, so the number of choices would not be constant. Cases fix that.

Common mistakes

MistakeExample of the errorFix
Adding when the choices happen together2 shirts and 3 pants give 2 + 3 = 5 outfitsAn outfit is a shirt and pants: 2 · 3 = 6.
Multiplying when the choices are alternativesOne elective from 5 art or 4 music courses: 5 · 4 = 20One choice from either list: 5 + 4 = 9.
Adding overlapping cases5 art and 4 music courses, but 1 course is in both lists: 9 choicesSubtract the overlap: 5 + 4 − 1 = 8.
Ignoring a restrictionThree-digit numbers with different digits: 10 · 9 · 8 = 720The first digit cannot be 0: 9 · 9 · 8 = 648.
Using the product rule when the number of choices changesEven codes: 9 · 8 · 5 = 360Split by whether the last digit is 0: 72 + 256 = 328.
Leaving out a casePasswords of 6 to 8 characters: only 368Add every length: 366 + 367 + 368.

Related ideas: counting the complement

Sometimes it is easier to count what you do not want and subtract. How many four-digit PINs (0000 to 9999) have at least one repeated digit?

10^4 = 10{,}000

Count all PINs: 4 positions with 10 choices each.

10 \cdot 9 \cdot 8 \cdot 7 = 5040

Count the PINs with no repeated digit.

10{,}000 - 5040 = 4960

Subtract to get the PINs with a repeat.

Answer: 4960 PINs. When options overlap, the sum rule becomes |A ∪ B| = |A| + |B| − |A ∩ B|, which is the start of the Inclusion-Exclusion Principle. Ordered choices without repeats are permutations, and the product rule also shows that a set with n elements has 2n subsets.

Practice problems

  1. A café has 6 hot drinks and 4 cold drinks. How many ways can you choose one drink?
  2. How many ways can you choose one hot drink from Problem 1 and one of 5 pastries?
  3. How many bit strings of length 10 are there?
  4. How many functions are there from a set with 3 elements to a set with 4 elements?
  5. Use the product rule to count the subsets of a set with 7 elements.
  6. How many four-digit PINs (0000 to 9999) have no repeated digit?
  7. A variable name is a single letter, or a letter followed by one digit. How many names are possible?
  8. How many three-digit numbers (100 to 999) are odd and have three different digits?
  9. How many passwords of length 3 or 4 can be made from the 26 lowercase letters, with repeats allowed?
  10. A meal is a starter (one of 4 soups or one of 3 salads), one of 6 mains, and either one of 5 desserts or no dessert. How many meals are possible?
Show answers

1.

6 + 4 = 10

Hot or cold, with no overlap (sum rule).

Answer: 10

2.

6 \cdot 5 = 30

A hot drink and then a pastry (product rule).

Answer: 30

3.

2^{10} = 1024

Each of the 10 positions is 0 or 1.

Answer: 1024

4.

4 \cdot 4 \cdot 4 = 4^3

Each of the 3 inputs can go to any of the 4 outputs.

4^3 = 64

Multiply.

Answer: 64

5.

2 \cdot 2 \cdots 2 = 2^7

For each of the 7 elements, decide in or out.

2^7 = 128

Multiply.

Answer: 128

6.

10 \cdot 9 \cdot 8 \cdot 7

Each new position cannot repeat an earlier digit.

90 \cdot 56 = 5040

Multiply in pairs: 10 · 9 = 90 and 8 · 7 = 56.

Answer: 5040

7.

26

Names with one character: a letter.

26 \cdot 10 = 260

Names with two characters: a letter and then a digit.

26 + 260 = 286

The two lengths are separate cases, so add.

Answer: 286

8.

5

Choose the last digit first: 1, 3, 5, 7 or 9.

8

The first digit cannot be 0 or the last digit.

8

The middle digit cannot match the other two.

5 \cdot 8 \cdot 8 = 320

Multiply. No cases are needed, since 0 is never the last digit.

Answer: 320

9.

26^3 = 17{,}576

Length 3.

26^4 = 456{,}976

Length 4.

17{,}576 + 456{,}976 = 474{,}552

Add the two lengths.

Answer: 474,552

10.

4 + 3 = 7

Starters: a soup or a salad.

5 + 1 = 6

Dessert options: one of 5 desserts, or none.

7 \cdot 6 \cdot 6 = 252

Starter, main and dessert option (product rule).

Answer: 252 meals

Sum and product rules FAQ

What is the difference between the sum rule and the product rule?

The sum rule counts one choice made from separate groups, so you add. The product rule counts a sequence of choices made one after another, so you multiply.

When do you add and when do you multiply in counting?

Add when the word is “or” and the cases cannot happen together. Multiply when the word is “and” or “then” and each step has a fixed number of choices.

Is the product rule the same as the fundamental counting principle?

Yes. The product rule, the multiplication principle and the fundamental counting principle are three names for the same idea: m ways followed by n ways gives mn ways.

What if the cases in the sum rule overlap?

Then adding counts the shared options twice. Subtract the overlap: |A ∪ B| = |A| + |B| − |A ∩ B|. This is the two-set case of inclusion-exclusion.

Summary

  • Sum rule: one choice from disjoint groups of sizes m and n can be made in m + n ways.
  • Product rule: a task of steps with n1, n2, …, nk choices can be done in n1n2⋯nk ways, as long as each count stays the same whatever came before.
  • Fill the most restricted positions first, and split into cases when the number of choices would change.
  • Counting the complement and subtracting is often faster.
  • If cases overlap, subtract the overlap instead of simply adding.

Previous lesson: RSA Encryption

Next lesson: Pigeonhole Principle

Back to the Discrete Math Index