Pascal Triangle Generator

Set a depth and read the rows, or click a single entry and find out what it counts. Every number here is a binomial coefficient C(n,k), computed with big integers so row 39 stays exact rather than rounding to a float. The lens buttons tint the triangle to show where Fibonacci, the powers of two, the triangular numbers, and the hockey stick identity live inside it.

Pascal triangle bench

Lens
C(n,k) = C(n-1,k-1) + C(n-1,k)

Every entry answers a counting question

The triangle looks decorative and behaves like a lookup table. The number sitting in row 5 at position 2 is 10, which is the number of two-person teams you get from five people. Read the same entry as a coefficient and it is the 10 in front of a³b² when you expand (a + b)⁵. Same value, two jobs, and the reason a printed triangle beats a factorial calculation for small numbers is that you never divide anything.

Both indices start at zero in the generator above, since that is how the binomial coefficient is defined and how every textbook writes the recurrence. The apex is row 0. The leftmost entry of any row is position 0.

What you wantWhere to lookWorked case
Ways to choose k from nRow n, position kRow 6 position 3 gives 20 three-card hands from six cards
Coefficients of an expansionRead row n from left to rightRow 4 gives 1, 4, 6, 4, 1 for (a + b)⁴
Total subsets of a setAdd up row nRow 8 adds to 256, the count of every subset of eight items
Coin flip probabilityRow n position k, divided by the row sum3 heads from 5 flips is 10 over 32, near 31 percent
A single large coefficientType the row number, click the entryRow 30 position 15 is 155,117,520

The row is a binomial expansion written sideways

Nothing about the triangle is separate from the algebra. Multiply (a + b) by itself n times and the coefficients you collect are exactly row n. The addition rule that builds the triangle is the same bookkeeping you do by hand when you gather like terms, which is why the two never disagree.

nRowExpansion of (a + b)n
011
11 1a + b
21 2 1a² + 2ab + b²
31 3 3 1a³ + 3a²b + 3ab² + b³
41 4 6 4 1a⁴ + 4a³b + 6a²b² + 4ab³ + b⁴
51 5 10 10 5 1a⁵ + 5a⁴b + 10a³b² + 10a²b³ + 5ab⁴ + b⁵

Click any entry in rows 0 through 8 above and the inspector prints the whole expansion for that row. Past row 8 it prints the single term instead, because a 20-term line wraps into unreadable soup on a phone.

Read down a diagonal and a different sequence appears

Rows get the attention, diagonals hold the sequences. The k-th diagonal is the sequence of C(n,k) as n climbs, and each one counts a shape one dimension up from the last.

DiagonalFirst termsFormulaWhat it counts
k = 01, 1, 1, 1, 1C(n,0)One way to pick nothing, at every size
k = 11, 2, 3, 4, 5C(n,1) = nCounting numbers, one pick from n
k = 21, 3, 6, 10, 15n(n-1)/2Triangular numbers, the handshakes in a room of n
k = 31, 4, 10, 20, 35n(n-1)(n-2)/6Tetrahedral numbers, cannonballs stacked in a pyramid
k = 41, 5, 15, 35, 70C(n,4)Pentatope numbers, the same idea in four dimensions

The triangular numbers lens paints the k = 2 diagonal on both sides, since C(n,2) and C(n,n-2) hold equal values. That mirroring is the symmetry rule: choosing 2 people to include is the same act as choosing n-2 to leave out.

Fibonacci hides on the shallow diagonals

The steep diagonals give polynomials. Tilt the angle and you get something else. Start at the left edge of row d and step up one row and right one position, over and over. Add what you land on and the result is a Fibonacci number.

d = 6 C(6,0) + C(5,1) + C(4,2) + C(3,3)1 + 5 + 6 + 1 = 13
d = 7 C(7,0) + C(6,1) + C(5,2) + C(4,3)1 + 6 + 10 + 4 = 21

Written once: the sum of C(d-k, k) over every k that fits is F(d+1). The Fibonacci lens tints alternate bands so the diagonals separate visually, and prints the running sums beneath the buttons. Why it works comes back to the addition rule. Splitting a diagonal into its two feeding diagonals reproduces the same recurrence Fibonacci runs on, one term built from the two before it.

The hockey stick is a running total, not a coincidence

Pick a cell that is not on the left edge. Walk up and left one step, then straight up the diagonal to the outer edge. Everything on that run adds to the cell you started from. The shape of the highlight is a handle and a blade, which is where the name came from.

Target C(7,3) = 35
Run C(2,2) + C(3,2) + C(4,2) + C(5,2) + C(6,2)1 + 3 + 6 + 10 + 15 = 35

Stated in general, the sum of C(i,r) for i running from r up to n equals C(n+1, r+1). The reason is a counting argument rather than an algebraic one. To choose r+1 items from n+1, sort the choices by which item is largest. Fix that largest item at position i+1 and the remaining r come from the i below it, giving C(i,r) choices. Add over every possible largest item and you have covered each selection exactly once. Select the hockey stick lens and click around, and every cell you press redraws the run that feeds it.

Color by remainder and the Sierpinski triangle appears

Set the lens to Remainders with a modulus of 2. Odd entries stay lit, even entries fade, and what remains is the Sierpinski gasket. Raise the depth to 32 and the self-similar holes get obvious.

Why the holes are exact. Kummer proved that the number of times a prime p divides C(n,k) equals the number of carries when you add k and n-k in base p. At p = 2 an entry is odd only when the addition needs no carrying, which happens only when the binary digits of k are a subset of the binary digits of n. That subset condition is a fractal rule, so the picture is a fractal.

The modulus accepts 2 through 12, and the prime values are the interesting ones. Try 3, then 5. Composite moduli produce patterns too, though they mix the behavior of the prime factors and read as noisier. Nothing here is an approximation, since the coloring tests the exact big-integer value against the modulus.

Where this generator stops

Everything runs in this tab. The recurrence, the lenses, and the export writers are all JavaScript on the page, so no row depth you type and no cell you click leaves your browser. Load the page, drop the network, and the triangle still builds.

Questions about Pascal triangle rows

Row numbering, precision limits, probability readings, and the identities the lenses draw.

Does the first row count as row 0 or row 1?

Row 0 in this generator, and in the mathematics it follows. The apex holds a single 1, and calling it row 0 is what makes C(n,k) line up with position k in row n. Some school textbooks number from 1 to keep the count of rows matching the row label, which shifts every reference by one and turns C(5,2) into a lookup in the sixth printed line. If you copied a formula from a source numbering from 1, subtract 1 from both the row and the position before reading it here.

Why do rows past 20 look cramped?

The generator switches to a dense cell size above 18 rows so a wide triangle still fits the panel. Row 30 carries 31 entries with the largest at nine digits, which is close to 300 characters across. The panel scrolls sideways when the row still overflows. Turn off the row index checkbox to reclaim a little width, and use the copy button rather than the screen if you need to read the digits carefully.

How do I read a probability off the triangle?

Divide an entry by its row sum. For a fair coin flipped n times, the chance of exactly k heads is C(n,k) over 2 to the n. Six flips landing on four heads reads as C(6,4) = 15 out of 64, near 23 percent. Turn on row sums so the denominator sits next to the row. This only holds for a fair coin, since the entries assume both outcomes are equally likely. A weighted coin needs the full binomial formula with the probability raised to the appropriate powers.

The values look wrong compared with my calculator. What happened?

Two causes account for nearly every mismatch. The first is index numbering, so check whether your source starts at row 1. The second is a calculator running out of precision. Standard floating point holds integers exactly only to about 9 quadrillion, and factorial-based routines overshoot that long before the answer does, since they compute n! and then divide. This page builds each row by adding the two entries above it, in big integers, so no intermediate value grows larger than the result.

What does the hockey stick identity give me in practice?

A closed form for a sum you would otherwise loop over. Counting how many ways to pick 3 items from any group between size 3 and size 12 means adding ten separate binomial coefficients, or reading C(13,4) = 715 directly. The same identity appears when you total the diagonals in combinatorics proofs and when a dynamic programming solution has a prefix sum over a binomial table. Click through the hockey stick lens and watch the run rebuild itself, since seeing the run collapse into one cell is what makes the identity stick.

Can I get the coefficients for an expansion with a coefficient in front, like (2x + 3)?

The triangle gives you the binomial part, and the rest is multiplication you do afterward. For (2x + 3) to the 4th, take row 4, which is 1, 4, 6, 4, 1, then multiply term k by 2 raised to (4-k) and 3 raised to k. The third term is 6 times 4 times 9, which is 216 x squared. The generator prints the pure coefficients because attaching the powers of 2 and 3 would hide the structure that makes the triangle readable.

Why is the middle entry always the largest in a row?

Because C(n,k) climbs while k is below n over 2 and falls after. The ratio between neighbouring entries is (n-k)/(k+1), which sits above 1 on the left half and below 1 on the right. Odd rows have two equal peaks at the centre, even rows a single one. The stat strip under the triangle reports the central entry as the largest for this reason, and its digit count is the fastest measure of how quickly the numbers grow.

Does the Fibonacci lens work at any depth?

The tinting does, and the printed sums are complete only for diagonals that fit inside the depth you set. Diagonal d needs rows up to d, so at 10 rows the sums for d = 0 through d = 9 are correct and anything beyond would be truncated. The legend prints at most the first twelve, and each one is computed from the rows currently on screen rather than from a stored Fibonacci list, so a wrong number would mean the triangle itself was wrong.

Which export format should I pick?

CSV for a spreadsheet, since each row lands as a ragged line of comma-separated values that Excel and Sheets both accept. JSON for code, where the triangle arrives as an array of arrays with a row count alongside. LaTeX for a document, ready to paste inside a math environment. Aligned text for a comment block or a terminal, padded so the pyramid holds its shape in a monospace font. All four are generated from the same big integers, so no format rounds.

Is there a way to get one coefficient without building the whole triangle?

Yes, and for a single large value that is the better route. C(n,k) equals the product of (n-i)/(i+1) for i from 0 to k-1, evaluated in that order so every partial result stays a whole number. Row 500 position 250 comes back in a few hundred operations that way, against 125,000 additions to build the triangle down to it. Reach for the triangle when you want the surrounding context and the patterns, and for the direct product when you want one number and nothing else.