Factorial
calculator.
Multiply every whole number from n down to 1, exactly, even with thousands of digits.
- Digits
- 68
- Trailing zeros
- 12
- Stirling
- 8.0529 × 10⁶⁷
52 factorial counts the ways to put 52 different things in a row, such as the orders of a shuffled deck of cards. Stirling's formula comes within 0.1601% of it, always a little low.
Growth of k!
Drag the point to change nUp is the number of digits, as log₁₀ of k!, for k from 0 to 80. At k = 52 it is 67.91, a value with 68 digits.
Working
- 1Multiply the whole numbers from n down to 152! = 52 × … × 2 × 1 = 80658175…000000, 68 digits
- 2Estimate it with Stirling's formula√(2π × 52) ×(52e)⁵²≈ 8.0529 × 10⁶⁷
- 3Count the factors of 5 for the trailing zeros⌊52 ÷ 5⌋ + ⌊52 ÷ 25⌋ + … = 12
- 4Check: count the zeros in the exact digits12 zeros at the end, and the factors of 5 gave 12
All 68 digits
To 5 significant figures: 8.0658 × 10⁶⁷
80,658,175,170,943,878,571,660,636,856,403,766,975,289,505,440,883,277,824,000,000,000,000
Prime factors of n!
How many times each prime divides it
| Prime | Times it divides |
|---|---|
| 2 | 49 |
| 3 | 23 |
| 5 | 12 |
| 7 | 8 |
| 11 | 4 |
| 13 | 4 |
| 17 | 3 |
| 19 | 2 |
Find n from a value of n!
10! = 3,628,800 exactly.
How it's worked out
The factorial of n, written , multiplies every whole number from n down to 1. It counts the ways to put n different things in a row, as OEIS A000142 records. Ten books fit on a shelf in = 3,628,800 orders.
By convention = 1. There is exactly one way to arrange nothing, and the value keeps = n × true when n is 1. The numbers grow very fast, so the tool keeps every digit up to , which has 16,326 digits, and estimates the size beyond that.
Each zero at the end of needs a 10, which is a 2 times a 5. There are always more 2s than 5s, so you count the 5s. Every multiple of 5 adds one, every multiple of 25 adds another, and so on. OEIS A027868 gives the rule.
The same count works for any prime, which gives the whole prime factorization. For example, 2 divides exactly 8 times. The prime table lists every prime up to n with its count.
Stirling's formula estimates without multiplying. It is the first term of the series in NIST DLMF 5.11, whose next factor is 1 + 1 over 12n, so the plain formula always comes out a little low.
For decimals, DLMF 5.4 sets = Γ(n + 1), where Γ is the gamma function. It also gives Γ of one half as √π, so = Γ(1.5) = 0.886227.
Two relatives use the same idea. The double factorial multiplies every other number, so = 8 × 6 × 4 × 2 = 384 (OEIS A006882). The subfactorial counts orders that leave nothing in its own place (OEIS A000166).
Worked examples
Jordan counts the orders of a shuffled deck
A deck has 52 different cards, so it can be shuffled into orders. Rounded to 5 significant figures, that is 8.0658 × 10⁶⁷, a number with 68 digits.
It ends in 12 zeros, one for each factor of 5 among the numbers up to 52. Stirling's formula gives 8.0529 × 10⁶⁷, which is 0.16% low.
Amara's spreadsheet stops at 170 factorial
Amara's spreadsheet shows but gives an error for . The reason is the largest ordinary floating-point number, about 1.8 × 10³⁰⁸, given as Number.MAX_VALUE in the MDN reference.
is about 7.2574 × 10³⁰⁶, just under that limit. is about 1.24 × 10³⁰⁹ and has 310 digits, so it does not fit. Here both are exact whole numbers, so comes out in full.
Four guests and a mixed-up hat check
Four guests leave their hats, and the attendant hands them back at random. There are = 24 ways to hand them back. The subfactorial = 9 counts the ways in which nobody gets their own hat.
So in 9 of the 24 orders everyone goes home with the wrong hat. With 10 guests the count is 1,334,961 out of 3,628,800. OEIS notes that is divided by e, rounded to the nearest whole number.
Reading your result
Digits grow faster than you expect. has 158 digits and has 2,568. The digit count is the number to read when you only need the size.
Zeros come from 5s. ends in 24 zeros and in 249, both exact even though the tool only estimates the size past .
Stirling gets better as n grows. For it is low by 0.0083%, close to the 1 in 12n the series predicts.
\(n{!}{!}\) is not a factorial taken twice. = 48, while is = 720. The double factorial is far smaller.
Going backwards. Type a value to find the n behind it: 3,628,800 is exactly. A value that is not a factorial, such as 1,000,000, sits between and .
Negative decimals work, negative whole numbers do not. Γ of one half is √π, so = 1.77245. At −1, −2 and the other negative whole numbers there is no value at all.
Common mistakes
- Thinking \(0{!}\) is 0. It is 1, the empty product, and many formulas break without it.
- Counting only the multiples of 5 for zeros. 25, 50, 75 and 100 each hold a second 5, which is why ends in 24 zeros, not fewer.
- Reading Stirling's value as exact. It is an estimate that is always a little low. Use the exact digits when you need the number itself.
- Mixing up \(n{!}{!}\) and \((n{!}){!}\). The first multiplies every other number; the second takes the factorial of a factorial.
Questions people ask
Sources
- OEIS A000142: factorial numbers
- OEIS A027868: number of trailing zeros in a factorial
- OEIS A006882: double factorials
- OEIS A000166: subfactorials or derangements
- NIST Digital Library of Mathematical Functions, section 5.11, Asymptotic Expansions
- NIST Digital Library of Mathematical Functions, section 5.4, Special Values and Extrema
- MDN Web Docs, Number.MAX_VALUE