A complete guide — with formulas and examples — to factorial, its recursive rule, BigInt for large numbers, double factorial, and subfactorial.
A factorial, denoted by an exclamation mark (!) after a whole number n, is the mathematical operation representing the product of all positive integers from 1 to n: n! = n × (n−1) × (n−2) × ... × 2 × 1. Factorial is one of the fundamental building blocks of combinatorics, permutations, combinations, probability calculations, and series expansions (e.g. the Taylor series).
What is the factorial formula and its recursive rule?
Quick answerThe factorial formula is n! = n × (n−1) × ... × 2 × 1; it can also be written recursively as n! = n × (n−1)!, with 0! = 1 as the base case (the empty-product rule). For very large n, the approximate value can be found with Stirling's formula: n! ≈ √(2πn) × (n/e)^n.
- Base case: 0! = 1, 1! = 1.
- Recursion: every n! is the previous (n−1)! multiplied by n.
- Growth rate: factorial grows even faster than an exponential function (a^n) — this is called super-exponential growth.
Why is factorial calculated with BigInt for large numbers?
Quick answerJavaScript's ordinary Number type can hold integers exactly only up to about 2^53 (≈9 quadrillion); this limit is exceeded around 18!–19!, and starting at 171! a Number overflows to Infinity. This tool performs every multiplication step with BigInt, producing an exact result, with every digit, up to 10000!.
In practice, this means that questions like "how many digits?" or "exactly which digits does it end in?" can only be answered correctly with BigInt (or similar arbitrary-precision arithmetic). A standard calculator or calculator app usually shows a rounded/approximate value after 20!; this tool instead stores the exact value and shows it on demand.
What are double factorial (n!!) and subfactorial (!n)?
Quick answerThe double factorial n!! is a product that decreases by 2 each step (e.g. 7!!=7×5×3×1=105). The subfactorial !n (derangement number) is the number of permutations of an n-element set in which no element stays in its original position (e.g. !4=9). Both are used in specialized combinatorics problems (series expansions, probability, distribution problems).
What is a multifactorial (n(k)!)?
Quick answerThe multifactorial n(k)! generalizes the double factorial to any step size k: n×(n−k)×(n−2k)×... down to a value between 1 and k (e.g. the triple factorial 9(3)!=9×6×3=162). k=1 gives the ordinary factorial and k=2 gives the double factorial, so n!! and n! are just special cases of this single formula.