Build Pascal’s triangle by adding, prove Pascal’s rule by asking whether a choice contains the first item, show that row n adds up to 2^n, and multiply out (a + b)^n with the binomial theorem by choosing which brackets give b.
Build Pascal’s triangle row by row by adding, and read n choose k from it.
Prove Pascal’s rule by sorting the choices according to whether they contain the first item.
Prove that row n of the triangle adds up to 2^n by counting the subsets of a set in two ways.
Multiply out (a + b)^n with the binomial theorem, and explain why its coefficients are the numbers n choose k.
Count the sequences of n right-or-wrong answers, or coin flips, with exactly k of one kind.
In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.
The question
A classifier is tried on 4 new examples, and each answer is right or wrong. Of the 16 possible patterns of rights and wrongs, how many have exactly 2 right? And why do the same numbers appear when \({(a + b)^4}\) is multiplied out?
From the last lesson
1. Write the formula for \(\binom{n}{k}\).
Show answer
\({\binom{n}{k} = \dfrac{n!}{k!\,(n-k)!}}\), which after cancelling is \({n(n-1)\cdots(n-k+1)}\) over \(k!\).
2. Why is \(\binom{n}{k}\) equal to \(\binom{n}{n-k}\)?
Show answer
Each choice of \(k\) items to keep is the same as a choice of the \({n - k}\) items to leave out, and this pairing matches the two kinds of choice one to one.
Intuition
Write the numbers \(\binom{n}{k}\) in rows: one row for each \(n\), and along the row \(k\) goes from 0 to \(n\). The rows are counted from 0, so the top row, a single 1, is row 0: there is one way to choose nothing from nothing. Centre the rows under each other and a triangle appears, called Pascal’s triangle.
M01.8.4-F1
Pascal’s triangle, rows 0 to 6. Every row starts and ends with 1, every number inside is the sum of the two above it, and the row sums are the doubling sequence.
Two patterns jump out. First, every number inside the triangle is the sum of the two numbers just above it: the 6 in row 4 is 3 plus 3, and the 10s in row 5 are 4 plus 6. So the whole triangle can be built by adding, without a single factorial. Second, the rows add up to 1, 2, 4, 8, 16, and so on: each row sum is twice the one before. This lesson proves both patterns by counting, and then finds the same numbers inside \({(a + b)^n}\).
Build it up
Step 1. Why a number is the sum of the two above it. Take \({\binom{4}{2} = 6}\), the choices of 2 items from \(\{a, b, c, d\}\). Sort them by one question: is \(a\) in the choice?
M01.8.4-F3
One question splits the choices into two groups that share nothing, and each group is a smaller count: the two numbers above in the triangle.
If \(a\) is in, one more item must be chosen from the other three, \(b\), \(c\) and \(d\): \(\binom{3}{1}\) ways. If \(a\) is out, both items must come from those three: \(\binom{3}{2}\) ways. No choice is in both groups, so by the addition principle of lesson M01.8.1 the two counts add:
And \(\binom{3}{1}\) and \(\binom{3}{2}\) are exactly the two numbers above the 6, in row 3.
Step 2. Why the rows double. A set of \(n\) elements has \(2^n\) subsets (lesson M01.8.1). Sort them by size: \(\binom{n}{0}\) have no elements, \(\binom{n}{1}\) have one, and so on up to \(\binom{n}{n}\) with all of them. Every subset has exactly one size, so the sizes split the subsets into groups that share nothing, and the row adds up to all the subsets: \(2^n\). For row 4, the 16 subsets of \(\{a, b, c, d\}\) are 1 empty, 4 single, 6 pairs, 4 triples and 1 whole set.
Step 3. The same numbers in a product. Lesson M01.1.2 read this off a cut-up square:
\[
(a+b)^2 = a^2 + 2ab + b^2.
\]
Its coefficients 1, 2, 1 are row 2. The next section shows that this is no accident.
The formal statement
NotePascal’s rule
For whole numbers \(n\) and \(k\) with \(k\) from 1 to \({n - 1}\),
Why. Take a set of \(n\) items and call one of them the first. Every choice of \(k\) items either contains the first item or does not. If it does, the other \({k - 1}\) items come from the remaining \({n - 1}\): that is \(\binom{n-1}{k-1}\) choices. If it does not, all \(k\) items come from the remaining \({n - 1}\): \(\binom{n-1}{k}\) choices. The two groups share nothing, so their sizes add. In the triangle, the two numbers on the right-hand side sit just above \(\binom{n}{k}\), which is why each inside number is the sum of the two above it. The ends of every row are \({\binom{n}{0} = 1}\) and \({\binom{n}{n} = 1}\).
NoteRow sums
For every whole number \(n\), with the counter \(k\) starting at 0,
\[
\sum_{k=0}^{n} \binom{n}{k} = 2^n.
\]
Why. Step 2 above: both sides count all the subsets of a set of \(n\) elements, the left side group by group according to size.
NoteThe binomial theorem
For every whole number \(n\) and any numbers \(a\) and \(b\),
Multiplying out with the distributive law of lesson M01.1.2 means: take one letter from each bracket, multiply what you took, do this in every possible way, and add up all the products. There are \(2^n\) ways to take the letters. A product in which \(k\) brackets gave \(b\) and the other \({n - k}\) gave \(a\) is \(a^{n-k} b^k\), whichever brackets they were. How many products are like that? As many as there are ways to choose which \(k\) of the \(n\) brackets give \(b\), and that is \(\binom{n}{k}\). Collecting the equal products, the term \(a^{n-k} b^k\) appears \(\binom{n}{k}\) times. With \({n = 2}\) the coefficients are 1, 2 and 1, which is the square of lesson M01.1.2 again.
At \({k = n}\) no bracket gave \(a\), so the \(a^0\) in that term stands for no factor at all: an empty product, which is 1 (lesson M01.7.4) even when \({a = 0}\). The same goes for \(b^0\) at \({k = 0}\). That is why the theorem reads \(0^0\) as 1, a case that lesson M01.4.1 left open.
The numbers \(\binom{n}{k}\) are often called binomial coefficients for this reason, and Python’s documentation of math.comb gives the same reason for the name.
Worked example
Multiply out \({(a + b)^3}\) by choosing letters. There are 3 brackets, so \({2^3 = 8}\) ways to take one letter from each. Sort the 8 products by how many brackets gave \(b\).
M01.8.4-F2
Every way of taking one letter from each of three brackets, sorted by how many gave \(b\). Each column collects into one term, and the sizes of the columns are row 3 of the triangle.
No bracket gives \(b\): only aaa, which is \(a^3\).
One bracket gives \(b\): aab, aba and baa, three products, each equal to \(a^2 b\). That is \({\binom{3}{1} = 3}\), one for each choice of the bracket that gives \(b\).
Two give \(b\): abb, bab and bba, each \(ab^2\): \({\binom{3}{2} = 3}\).
All three give \(b\): bbb, which is \(b^3\).
So
\[
(a+b)^3 = a^3 + 3a^2 b + 3ab^2 + b^3.
\]
Now \({(a + b)^4}\), read off row 4. Row 4 is 1, 4, 6, 4, 1, so
Check with numbers. Put \({a = 2}\) and \({b = 1}\). The left side is \({3^4 = 81}\). The right side is
\[
16 + 32 + 24 + 8 + 1 = 81.
\]
Put \({a = 1}\) and \({b = 1}\) instead, and the theorem turns into the row sum: \(2^4\) is 16, the sum of row 4.
The question. A pattern of 4 answers, each right or wrong, is a choice of right or wrong for each of 4 places, just like a choice of letter for each of 4 brackets. Exactly 2 right means choosing which 2 of the 4 places are right: \({\binom{4}{2} = 6}\) patterns out of 16. The counts for 0 to 4 right are row 4, 1, 4, 6, 4 and 1. If all 16 patterns are equally likely, as they are for four flips of a fair coin, 6 of the 16 have exactly two heads. Lesson M06.8.1 builds the binomial distribution, the model for the number of successes in \(n\) tries, on exactly this count.
Code
First the triangle from scratch, by addition alone: each new row starts with 1, adds neighbouring pairs of the row above, and ends with 1.
def next_row(row):# Every row starts with 1 ... new = [1]# ... adds the two numbers above ...for k inrange(1, len(row)): new.append(row[k -1] + row[k])# ... and ends with 1. new.append(1)return new# Start from row 0 and add rows 1 to 6.rows = [[1]]for n inrange(1, 7): rows.append(next_row(rows[-1]))for n inrange(7):print(n, rows[n], "sum", sum(rows[n]))
0 [1] sum 1
1 [1, 1] sum 2
2 [1, 2, 1] sum 4
3 [1, 3, 3, 1] sum 8
4 [1, 4, 6, 4, 1] sum 16
5 [1, 5, 10, 10, 5, 1] sum 32
6 [1, 6, 15, 20, 15, 6, 1] sum 64
Now check every number against math.comb, and count right-or-wrong patterns directly: itertools.product("RW", repeat=4) lists the 16 patterns, and .count("R") counts the rights in one.
import itertoolsimport mathmatches =Truefor n inrange(7):for k inrange(n +1):if rows[n][k] != math.comb(n, k): matches =Falseprint("agrees with math.comb:", matches)# counts[k]: the patterns with k right.counts = [0, 0, 0, 0, 0]for pattern in itertools.product("RW", repeat=4): right = pattern.count("R") counts[right] = counts[right] +1print(counts, "out of", sum(counts))
agrees with math.comb: True
[1, 4, 6, 4, 1] out of 16
Last, the binomial theorem with numbers: add up its terms for \({a = 2}\), \({b = 1}\) and \({n = 4}\), and compare with \({(a + b)^n}\) worked out directly.
a, b, n =2, 1, 4total =0for k inrange(n +1):# The term with b from k brackets. term = math.comb(n, k) * a ** (n - k) term = term * b ** kprint("k =", k, "term", term) total = total + termprint(total, (a + b) ** n)
k = 0 term 16
k = 1 term 32
k = 2 term 24
k = 3 term 8
k = 4 term 1
81 81
Explore
The choose-and-arrange explorer lives in lesson M01.8.3. Switch “order matters” and “repeats allowed” off and set 4 items: as the number of places goes from 1 to 3, the count runs 4, 6, 4, the inside of row 4 of the triangle.
Pitfalls
M01.8.4-F4
Wrong beside right, with \({a = 2}\) and \({b = 1}\). Raising each part to the fourth power keeps only the end terms, 17 of the true 81.
“\({(a + b)^n}\) is \({a^n + b^n}\).”
Only the two end terms survive that shortcut. The products that take some \(a\)’s and some \(b\)’s, all \(\binom{n}{k}\) of each kind, are dropped. With \({a = 2}\), \({b = 1}\) and \({n = 4}\) the shortcut gives 17 instead of 81, and the missing middle terms are most of the total. The case \({n = 2}\) is the familiar warning that \({(a + b)^2}\) is not \({a^2 + b^2}\).
“Row 4 of the triangle is 1, 3, 3, 1.”
That is the fourth row from the top, but here it is row 3. This course, like Hammack, counts the rows from 0, so that row \(n\) holds the numbers \(\binom{n}{k}\) and starts 1, \(n\). Row 4 is 1, 4, 6, 4, 1, the coefficients of \({(a + b)^4}\). Some books, OpenStax among them, count the rows from 1, so check how a text counts. A quick check here: from row 1 on, the second number of row \(n\) is \(n\).
“The binomial theorem only works for \({a + b}\) with letters.”
It works for any two numbers or expressions in place of \(a\) and \(b\), signs and numbers included, as long as each is raised as a whole. For \({(2x - 1)^3}\), take \({a = 2x}\) and \({b = -1}\):
1. How is each number inside Pascal’s triangle made from the row above?
Show answer
It is the sum of the two numbers just above it. Each row also starts and ends with 1.
2. Why is \(\binom{n}{k}\) the sum \(\binom{n-1}{k-1}\) plus \(\binom{n-1}{k}\)?
Show answer
A choice of \(k\) items either contains the first item, and then the other \({k - 1}\) come from the other \({n - 1}\) items, or it does not, and then all \(k\) do. The two cases share nothing, so their counts add.
3. What does row \(n\) of the triangle add up to, and why?
Show answer
\(2^n\). The row lists how many subsets of an \(n\)-element set have each size, so together they count all its subsets, and there are \(2^n\) of those.
4. What is the coefficient of \(a^2 b^2\) in \({(a + b)^4}\)?
Show answer
6, which is \(\binom{4}{2}\): the number of ways to choose which 2 of the 4 brackets give \(b\).
5. How many sequences of 4 coin flips have exactly 2 heads?
Show answer
\({\binom{4}{2} = 6}\): choose which 2 of the 4 flips are heads. They are HHTT, HTHT, HTTH, THHT, THTH and TTHH.
Exercises
1.★ Row 6 is 1, 6, 15, 20, 15, 6, 1. Build row 7 by adding, check its sum, and use it to write down \(\binom{7}{3}\).
Show solution
Start and end with 1, and add neighbours: 1 and 6 make 7, 6 and 15 make 21, 15 and 20 make 35, and the second half mirrors the first. Row 7 is 1, 7, 21, 35, 35, 21, 7, 1. Its sum is 128, which is \(2^7\). Counting from \({k = 0}\), the fourth number is \({\binom{7}{3} = 35}\).
2.★★ Multiply out \({(x + 2)^3}\) with the binomial theorem, and check your answer at \({x = 1}\).
Show solution
Take \({a = x}\) and \({b = 2}\), with row 3, which is 1, 3, 3, 1:
At \({x = 1}\) the left side is \({3^3 = 27}\), and the right side is
\[
1 + 6 + 12 + 8 = 27.
\]
3.★★★ A classifier answers 10 test examples, each right or wrong. How many patterns have exactly 8 right, and how many have at least 8 right? Then put \({a = 1}\) and \({b = -1}\) into the binomial theorem to show that in any row from row 1 on, the numbers in even places (\(k\) = 0, 2, 4, …) add up to the same total as those in odd places. Check it on row 4.
Show solution
Exactly 8 right: choose which 8 of the 10 are right, \({\binom{10}{8} = 45}\) patterns. At least 8 right means exactly 8, 9 or 10, three cases that share nothing, so
With \({a = 1}\) and \({b = -1}\) the left side of the theorem is \({0^n = 0}\) for \({n \ge 1}\), and on the right each term is \(\binom{n}{k}\) times \({(-1)^k}\), which is \({+1}\) for even \(k\) and \({-1}\) for odd \(k\). So the even-place numbers minus the odd-place numbers make 0: the two totals are equal. In row 4 the even places hold 1, 6 and 1, which make 8, and the odd places hold 4 and 4, which also make 8. Each total is half of \(2^n\).
Summary card
The numbers \(\binom{n}{k}\) form a triangle built by adding, and they are the coefficients of \({(a + b)^n}\).
M01.8.4-F1
Add the two above; the rows double.
Pascal’s rule.\(\binom{n}{k}\) is \(\binom{n-1}{k-1}\) plus \(\binom{n-1}{k}\).
Counting patterns.\(\binom{n}{k}\) sequences of \(n\) flips have exactly \(k\) heads.
Sources and next steps
Sources. Each was opened and checked against this lesson on 12 November 2026.
Richard Hammack, Book of Proof, third edition. Section 3.6: Pascal’s formula (Equation 3.3) with the argument by whether a subset contains a chosen element, the triangle in Figure 3.3 with its top row called Row 0, the symmetry of each row (Equation 3.4), and the binomial theorem (Theorem 3.1), which the book states there without proof; its Exercise 6 asks for the row sum \(2^n\) by counting subsets. Section 3.10 names the argument a combinatorial proof.
Jay Abramson and others, Algebra and Trigonometry 2e, Section 13.6 (OpenStax). Binomial coefficients, the binomial theorem written as a sum from \({k = 0}\) to \(n\), and Pascal’s triangle, whose rows it counts from 1 (its row 2 is the row of two 1’s).
Python 3.12 documentation, math.comb: “also called the binomial coefficient because it is equivalent to the coefficient of k-th term in polynomial expansion of \({(1 + x)^n}\)”.
Next. This closes the module. The same counts return in probability: M06.2 counts equally likely outcomes with them, and M06.8 builds the binomial distribution on them. Calculus uses the binomial theorem in M04.3 to find the slope of \(x^n\).