Integer Partition Calculator

p(n) exactly, with the partitions drawn.

  • Exact p(n) to 5000
  • Lists the sums
  • Ferrers diagrams
A small rounded clay table with piles of soft clay pebbles sorted into several different groupings of the same total, in soft daylight.

The guide

Adding up to a number without caring about order: 4 has five ways, 40 has 37,338

A partition forgets the order of its summands, which turns a simple doubling count into one that has no closed formula but can still be computed exactly.

  • 627 ways to write 20 as a sum when order is ignored
  • 37,338 partitions of 40, the longest list the page shows
  • 64 and 64 partitions of 20 into distinct parts and into odd parts
  • 7 partitions of 20 that read the same across and down
  • 1.4 percent how far the leading formula overshoots at n = 1000
Read the full guide Fold the guide 7 min · 13 sources

Take the number 4. You can write it as 4, as 3 + 1, as 2 + 2, as 2 + 1 + 1, or as 1 + 1 + 1 + 1. That is five ways, and a sixth never turns up once you agree that 1 + 3 is the same sum as 3 + 1. Each of those sums is called a partition of 4, and the number of them is written p(4).

Two ways to count a sum

The agreement about order is the whole definition. Let order matter and the same objects get a different name: they become compositions, and 1 + 3 and 3 + 1 count as two. Every positive whole number n has exactly 2^(n-1) compositions, so 4 has 8 where it has 5 partitions. The gap widens quickly. The number 6 has 32 compositions but only 11 partitions.

A composition is easy to count because it is settled by one yes or no per gap: write n as a row of ones and decide, at each of the n - 1 gaps, whether to cut there. Partitions allow no such trick. Once order is thrown away, many of those cuts describe the same sum, and nobody has found a closed expression that returns the right count for every n.

What exists instead is a recurrence that computes p(n) exactly, plus an approximation that is accurate for large n. Both are the subject of the next section. The early values run 1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, and p(30) is already 5604.

The seven partitions of 5 show how a list stays honest. Written with the largest part first, they are 5, then 4 + 1, 3 + 2, 3 + 1 + 1, 2 + 2 + 1, 2 + 1 + 1 + 1 and 1 + 1 + 1 + 1 + 1. Fixing an order for the list is what makes it hard to skip a sum or write one twice.

Counting without listing

Listing stops being practical fast. The partitions of 40 number 37,338, which is still a page you can scroll. The partitions of 100 number 190,569,292, and nobody wants that list. Euler found a way to get the count while writing down none of the sums.

His pentagonal number theorem says that the product (1 - x)(1 - x^2)(1 - x^3) and so on forever equals 1 - x - x^2 + x^5 + x^7 - x^12 - x^15 + and so on. The exponents 1, 2, 5, 7, 12, 15 are generalised pentagonal numbers, given by k(3k - 1)/2 for k = 1, -1, 2, -2 and onward. Almost every power of x cancels away.

That product is the reciprocal of the generating function for p. Multiply the two and the result is 1, and matching coefficients turns into a rule: p(n) = p(n - 1) + p(n - 2) - p(n - 5) - p(n - 7) + p(n - 12) + p(n - 15) and so on, with signs in pairs, stopping when an index goes below zero. Try it for 10. The usable terms are p(9) + p(8) - p(5) - p(3), which is 30 + 22 - 7 - 3 = 42. Four terms replace a list of 42 sums.

Drop the second pentagonal number from that rule and the answer is wrong, which is a handy way to see that every term earns its place. The terms of one rule line also stay few: the pentagonal numbers up to n grow only like the square root of n, and up to 5000 there are 114 of them.

Why do the signs work? Franklin’s argument looks at partitions into distinct parts and pairs off those with an even number of parts against those with an odd number. All pairs cancel except when n is a pentagonal number. The coefficient of x^5 is +1 because 5 splits into an even number of distinct parts twice (4 + 1 and 3 + 2) and an odd number once (5 alone). The coefficient of x^12 is -1 because the counts are seven and eight.

Size is the next trap. A double-precision number holds whole numbers exactly only up to 2^53 - 1. By the tool’s count, p(300) = 9,253,082,936,723,602 is the first value past that line, and p(5000) has 75 digits. Whole numbers of any length need BigInt, which the browser provides for values too large for an ordinary number.

For a feel of the growth, the leading term found by Hardy and Ramanujan in 1918 is p(n) close to exp(pi times the square root of 2n/3), divided by 4n times the square root of 3. The exponent grows with the square root of n, so digits grow slowly: 9 digits at n = 100, 32 at n = 1000, 75 at n = 5000. At n = 1000 the leading term lands near 2.4402 x 10^31, about 1.4 percent above the exact value.

The history is a good reminder that tables came before proofs. Percy MacMahon published the number of unrestricted partitions for the first 200 integers, tables that proved extremely useful to Hardy and Littlewood. Ramanujan used MacMahon’s data to conjecture patterns. One of his discoveries is that p(n) is a multiple of 5 whenever n ends in 4 or 9. The values p(4) = 5, p(9) = 30, p(14) = 135 and p(19) = 490 all fit. A later convergent series by Rademacher gives the exact value.

Odd parts and distinct parts

Restrictions give the subject its surprises. Take the 22 partitions of 8. Six use only odd parts: 7 + 1, 5 + 3, 5 + 1 + 1 + 1, 3 + 3 + 1 + 1, 3 + 1 + 1 + 1 + 1 + 1 and eight ones. Six use no part twice: 8, 7 + 1, 6 + 2, 5 + 3, 5 + 2 + 1 and 4 + 3 + 1.

That tie is no accident. For every n the two counts match, a result Euler proved in 1748 and later generalised to Glaisher’s theorem. For n = 20 the pair is 64 and 64.

A bijection explains it. Group the repeated odd parts and write each repeat count in binary. In 5 + 3 + 3 + 3 + 1 + 1, which adds to 16, the part 3 appears three times, and 3 is 2 + 1 in binary, so it becomes 3 x 2 = 6 and 3 x 1 = 3. The part 1 appears twice, which becomes 1 x 2 = 2. The result is 6 + 5 + 3 + 2, all different. Run it backward by splitting any even part in half until none is left: 6 becomes 3 + 3, 2 becomes 1 + 1, and the odd partition returns.

The calculator counts the two sides separately, one over odd parts and one with a pentagonal-style recurrence on the distinct side, and shows them next to each other. The equality is something you read off the screen rather than something the page assumes.

Rows into columns

A partition can be drawn as rows of dots, longest row on top. The picture is called a Ferrers diagram, after Norman Macleod Ferrers; the version with boxes is a Young diagram, after Alfred Young. MacTutor’s biography of Ferrers shows the move that matters. Take 15 = 6 + 4 + 3 + 2, reflect the diagram in the diagonal through its top left corner, and the rows become the columns of 15 = 4 + 4 + 3 + 2 + 1 + 1.

That second partition is the conjugate of the first. Reflecting twice gives the original back, so conjugation sorts the partitions of n into pairs. Pairs of 4 are 4 with 1 + 1 + 1 + 1, and 3 + 1 with 2 + 1 + 1. The partition 2 + 2 pairs with itself.

One payoff is that the number of partitions of n into exactly m parts equals the number with largest part m. Counting parts and counting sizes are one problem seen from two sides, and a single recurrence, p_k(n) = p_k(n - k) + p_(k-1)(n - 1), covers both.

Partitions that equal their own conjugate are called self-conjugate, and they have their own tie to the earlier theme: their number equals the number of partitions into distinct odd parts. Fold each odd part around the corner of a diagram into an L-shape and the pieces nest into a symmetric figure. The pair 9 + 7 + 3 and 5 + 5 + 4 + 3 + 2 shows it, since the L-shapes along the diagonal of the second hold 9, 7 and 3 blocks. For n = 20 there are 7.

A worked example, and the limits

Enter n = 20 and k = 3 to reproduce a full set of numbers. The calculator reports p(20) = 627, with 64 partitions into distinct parts, 64 into odd parts and 7 self-conjugate. It reports 44 partitions into at most three parts, which matches the nearest integer to (20 + 3)^2 / 12 = 44.08, and 33 into exactly three. The single partition into one part and the 10 into exactly two bring that 33 to 44.

Counts run for n up to 5000, in a background thread so typing stays smooth. The list and the diagrams stop at n = 40, where the longest list holds 37,338 rows. The page does not prove congruences, does not evaluate the exact Hardy-Ramanujan-Rademacher series, and does not list partitions beyond n = 40. The leading-term ratio it shows is an approximation and is labelled as one. Choosing and arranging items, where order may matter, is a different job.

Sources

Every source consulted for this guide. Links checked November 10, 2026.

  1. Integer partition Wikipedia
  2. Pentagonal number theorem Wikipedia
  3. Partition function (number theory) Wikipedia
  4. Composition (combinatorics) Wikipedia
  5. A000041 - OEIS The On-Line Encyclopedia of Integer Sequences (OEIS Foundation)
  6. A000009 - OEIS The On-Line Encyclopedia of Integer Sequences (OEIS Foundation)
  7. A000700 - OEIS The On-Line Encyclopedia of Integer Sequences (OEIS Foundation)
  8. DLMF: 27.14 Unrestricted Partitions NIST Digital Library of Mathematical Functions
  9. Norman Ferrers (1829 - 1903) - Biography MacTutor History of Mathematics, University of St Andrews
  10. Percy MacMahon (1854 - 1929) - Biography MacTutor History of Mathematics, University of St Andrews
  11. Srinivasa Ramanujan (1887 - 1920) - Biography MacTutor History of Mathematics, University of St Andrews
  12. BigInt MDN Web Docs
  13. Web Workers API MDN Web Docs