Big factorial calculator
The factorial of a non-negative integer n, written n!, is the product of every whole number from n down to 1. It is the cornerstone of combinatorics: counting permutations (ordered arrangements) and combinations (unordered selections), computing binomial coefficients, deriving the Taylor-series coefficients of many standard functions, and analysing the complexity of sorting algorithms. This tool goes beyond a basic factorial button by using exact arbitrary-precision arithmetic via JavaScript BigInt, so the complete integer is displayed — no rounding, no ellipsis, just every digit — for any n up to 10,000.
How it works
For n up to 10,000 the calculator runs a straightforward BigInt loop:
acc = 1
for i = 2 to n:
acc = acc * i
return acc
Because ordinary JavaScript numbers are 64-bit IEEE 754 floats, they lose precision above 2^53 (roughly 9 × 10^15). BigInt stores integers of arbitrary length as exact signed integers, so 1000! — which has 2,568 digits — is computed digit-for-digit with no approximation. The digit count comes from the length of the decimal string.
The scientific notation display extracts the first 6 significant figures of the mantissa from the BigInt string and appends e+exp. The log base 10 is computed as the sum of log10(k) for k from 2 to n, which is exact to floating-point precision and matches the BigInt result to many decimal places.
Above 10,000 the same log-sum method provides a highly accurate approximation and reports the digit count without materialising the full integer.
Step-by-step working
For n up to 15 the tool expands each multiplication so you can follow every step:
5! = 5 x 4 x 3 x 2 x 1
= 1 x 2 = 2
= 2 x 3 = 6
= 6 x 4 = 24
= 24 x 5 = 120
This is useful when learning factorials or checking work by hand.
Formula note
The formal recursive definition is:
0! = 1
n! = n * (n - 1)! for n >= 1
The base case 0! = 1 is not arbitrary — it is the number of ways to arrange zero objects (there is exactly one such arrangement: do nothing). It also keeps combination and permutation formulas consistent at boundary cases such as C(n, 0) = 1.
A useful approximation for very large n is Stirling’s formula:
ln(n!) is approximately n * ln(n) - n + 0.5 * ln(2 * pi * n)
The relative error shrinks as n grows, making it accurate to better than 1 % for n above 10. The log-sum method used here is even more accurate.
Worked example
For n = 20:
20! = 2,432,902,008,176,640,000
That is exactly 19 digits. In scientific notation: 2.432902e+18.
log10(20!) = 18.386 (the exponent tells you there are 18 + 1 = 19 digits before the decimal point if you were to write the number in plain form).
For n = 52 (a deck of cards):
52! has 68 digits and equals approximately 8.066e+67. The number of atoms in the observable universe is about 10^80, so 52! is still smaller — but it vastly exceeds the number of seconds since the Big Bang (roughly 4 × 10^17). Every time a deck is well-shuffled the arrangement is almost certainly unique in all of human history.
| n | n! | Digits | Notable context |
|---|---|---|---|
| 5 | 120 | 3 | Permutations of 5 items |
| 10 | 3,628,800 | 7 | Seconds in six weeks (approx.) |
| 13 | 6,227,020,800 | 10 | Exceeds world population |
| 20 | 2,432,902,008,176,640,000 | 19 | Common probability benchmark |
| 52 | ~8.07e+67 | 68 | Deck of cards shuffles |
| 100 | ~9.33e+157 | 158 | Classic combinatorics example |
| 1000 | ~4.02e+2567 | 2,568 | Often cited in computer science |
All calculations run locally in your browser — no number is ever sent to a server.