🔧 Operation
Factorial computes n!; double factorial computes n!!;
permutations compute P(n, r) = n × (n-1) × … × (n-r+1); combinations
compute C(n, r) = P(n, r) / r!.
📝 Inputs
Inputs must be non-negative integers. Decimal or non-numeric values are rejected.
📤 Result
n {{ needsR ? "and r " : "" }}— the result will appear
here.
📊 Details
🔢 Full decimal value
{{ rawResult }}
Exact decimal integer — no rounding. Click Copy to copy the full value.
ℹ️ About Factorial Calculator
What does this calculator do?
This tool computes four classical combinatorial quantities — factorial
(n!), double factorial (n!!),
permutations (nPr), and
combinations (nCr) — for any non-negative integer
n up to 10000. All arithmetic is performed with
JavaScript BigInt
so the results are exact decimal integers, not floating-point approximations. At
n = 10000 the factorial has
35,660 digits — far beyond what any double-precision float can
represent.
For example, 10! = 3,628,800 (7 digits), 52! has 68 digits,
and 1000! has 2,568 digits. The calculator returns the full decimal string
plus a leading-digits preview for very large results.
Definitions
- Factorial —
n! = n × (n-1) × (n-2) × … × 2 × 1, with the convention0! = 1. Counts the orderings ofndistinct items. - Double factorial —
n!! = n × (n-2) × (n-4) × …, stopping at2whennis even and1whennis odd.0!! = 1!! = 1by convention. Appears in trigonometric integrals, beta-function identities, and combinatorial sums. - Permutations —
P(n, r) = n! / (n-r)! = n × (n-1) × … × (n-r+1). Number of ordered arrangements ofritems chosen fromn. - Combinations —
C(n, r) = n! / (r! · (n-r)!). Number of unordered selections ofritems fromn; also written(n choose r)or(n, r)with a binomial coefficient.
Worked examples
0! = 1(empty product convention).5! = 120.10! = 3,628,800— seven digits, the cap of every six-digit display calculator.20! = 2,432,902,008,176,640,000— already pastNumber.MAX_SAFE_INTEGER; BigInt keeps it exact.52!≈8.0658 × 10⁶⁷— the number of distinct shuffles of a standard 52-card deck.100!ends in 24 trailing zeros (Legendre's formula: 100/5 + 100/25 = 24).1000!has 2,568 digits.5!! = 5 × 3 × 1 = 15.6!! = 6 × 4 × 2 = 48.P(10, 3) = 10 × 9 × 8 = 720.C(52, 5) = 2,598,960— the number of distinct 5-card poker hands.C(n, 0) = C(n, n) = 1for anyn.
Why BigInt instead of floats?
IEEE-754 double-precision floats only hold integers exactly up to
2⁵³ − 1 = 9,007,199,254,740,991 (≈ 9 × 10¹⁵). After that, every
integer is rounded to the nearest representable value. 20! still happens
to be exactly representable because its binary expansion has trailing zeros, but
21! is already wrong by 1 — and 171! overflows the
double-precision range entirely and becomes Infinity.
BigInt is JavaScript's arbitrary-precision integer type. There is no
rounding and no overflow — you get the exact decimal digits no matter how many there
are. This calculator multiplies BigInts in a tight loop, then serialises the result
as a decimal string so the API can return it verbatim.
How permutations and combinations are computed
A naïve implementation of nPr and nCr would compute three
factorials (n!, r!, (n-r)!) and divide. For
n = 10000 that wastes time on a 35,660-digit numerator.
Instead this tool uses the falling factorial identity
nPr = n × (n-1) × … × (n-r+1), which has exactly r factors.
nCr is then nPr / r! — BigInt division is exact here because
the binomial coefficient is always an integer. The calculator also applies the
symmetry nCr(n, r) = nCr(n, n-r) and picks the smaller r, so
C(10000, 9999) is just as fast as C(10000, 1).
Stirling's approximation
For order-of-magnitude estimates without computing the exact value, Stirling's approximation gives a closed-form lower-bound asymptotic:
n! ≈ √(2πn) · (n/e)^n
For n = 100:
Stirling ≈ 9.32485 × 10¹⁵⁷
Exact = 9.33262 × 10¹⁵⁷
Stirling is roughly 1/(12n) too low and is exact to about 7 digits for
n = 50 and 14 digits for n = 1000. It is the standard
reference identity for proving asymptotic bounds in algorithm analysis, statistical
mechanics, and information theory. This calculator returns the exact value — use
Stirling on paper when you only need the order of magnitude.
Use cases
- Combinatorics homework. Verify ordered/unordered counts without scribbling 9-by-9 multiplications.
- Probability problems. Card hand counts, lottery odds, and birthday-paradox style identities all reduce to
nCrornPr. - Algorithm analysis. Cross-check Stirling-derived asymptotics against the exact factorial.
- Number theory. Inspect trailing-zero counts of
n!(Legendre's formula), digit counts, and growth rates. - Stress-test arbitrary-precision arithmetic. 10000! is a 35,660-digit integer — a good sanity check for any BigInt-based pipeline.
Limitations
- Integers only. No gamma-function extension for non-integer
n— fractional input is rejected. - n ≤ 10,000. Hard cap to keep the response size bounded. 10000! is 35,660 digits — about 35 KB of text.
- r ≤ n. Permutations and combinations require
0 ≤ r ≤ n. - Decimal string output. Results larger than 100 digits also surface a leading-digits preview (first 30 digits) for readability; the full value is still returned in the
resultfield.
References
- Factorial (Wikipedia) — definition, Stirling's approximation, Legendre's trailing-zero formula.
- Double factorial (Wikipedia) — definition and identities.
- Permutation and Combination on Wikipedia.
- Binomial coefficient — the algebraic identity underlying
nCr. - MDN —
BigInt— the arbitrary-precision integer type used here.
API Usage Example:
POST /api/tools/math/factorial-calculator
Content-Type: application/json
{
"operation": "factorial",
"n": 10
}