Factorial Calculator

Free factorial calculator for n! up to 170. Step-by-step results, BigInt support, Stirling approximation, permutations and combinations.

A factorial calculator computes n! — the product of all positive integers from 1 up to n. The function appears throughout combinatorics, probability, calculus (Taylor series), and statistics, and it grows faster than any polynomial or simple exponential. This calculator accepts integer inputs from 0 to 170 with full standard-precision output; for n >170 the result exceeds IEEE-754 double range (~1.8 × 10³⁰⁸), so larger inputs use BigInt arithmetic to preserve every digit. Each calculation produces the final value plus the step-by-step expansion so you can verify the multiplication by hand, useful for homework checks, combinatorics setup, and probability problems.

What is a Factorial?

A factorial is the product of all positive integers from 1 to a given non-negative integer n. It is written n! and pronounced "n factorial" — the exclamation-mark notation was introduced by French mathematician Christian Kramp in 1808 and stuck because it is concise and unmistakable on the page. By convention 0! = 1; this is the empty product, the multiplicative analogue of the empty sum being 0, and it is required for many combinatorial formulas like C(n,0) = 1 and the Taylor series for e^x to behave correctly at n = 0.

How to calculate Factorial?

To calculate the factorial manually:

  1. Pick the non-negative integer n you want the factorial of.
  2. List the integers from 1 up to n.
  3. Multiply them in sequence: 1 × 2 × 3 × ... × n. Iterative left-to-right multiplication is the simplest and avoids deep recursion stacks.
  4. The final product is n!.
  5. For verification, this calculator also displays the full expansion so you can check each multiplication step.

The Factorial formula:

n! = n × (n-1) × (n-2) × ... × 2 × 1, with the base case 0! = 1.

Example

To calculate 5!:

5! = 5 × 4 × 3 × 2 × 1 = 120

So 5! = 120.

Change n in the input field to compute any other factorial; the expansion below the result will update accordingly.

Special cases:

  • 0! = 1 (by definition, the empty product)
  • 1! = 1
  • Factorials grow very rapidly: 10! = 3,628,800; 20! ≈ 2.43 × 10¹⁸; 70! ≈ 1.2 × 10¹⁰⁰

Applications of Factorials:

  • Permutations: n! arrangements of n distinct objects
  • Combinations: C(n,k) = n! / (k! × (n−k)!)
  • Probability and statistics (multinomial coefficients, expected values)
  • Taylor series expansions: e^x = Σ xⁿ / n!
  • Stirling's approximation for large factorials: n! ≈ √(2πn) × (n/e)ⁿ

Frequently Asked Questions

Three independent arguments all point to 0! = 1, which is why mathematicians fixed the convention rather than leaving 0! undefined. (1) Empty product: in algebra, multiplying together zero numbers gives the multiplicative identity, which is 1 — the same logic that makes x⁰ = 1 for any nonzero x. (2) Combinatorial: C(n,0) counts the number of ways to choose nothing from n items, which is exactly 1 (the empty selection). The formula C(n,0) = n! / (0! × n!) only equals 1 if 0! = 1. (3) Recursive consistency: the rule n! = n × (n−1)! must hold at n = 1, giving 1! = 1 × 0!, so 0! must be 1 for 1! = 1 to come out right. The same logic extends through the gamma function Γ(n+1) = n!, where Γ(1) = 1 by direct integration. So 0! = 1 is not an arbitrary choice — it is the only value that keeps every related formula self-consistent.

Because 170! ≈ 7.257 × 10³⁰⁶ is the largest factorial that fits inside a standard IEEE-754 double-precision floating-point number, whose maximum is about 1.798 × 10³⁰⁸. 171! ≈ 1.241 × 10³⁰⁹ overflows to Infinity in JavaScript, Excel, and most calculators. To handle larger n, the calculation switches to BigInt — an arbitrary-precision integer type built into modern JavaScript — which can compute any factorial subject only to memory and time. 1000! has 2568 digits and takes a fraction of a second; 100000! has 456,574 digits and takes a few seconds. For very large factorials you usually do not want the exact value — you want Stirling's approximation log(n!) ≈ n log n − n + 0.5 log(2πn), accurate to fractions of a percent even for moderate n.

Stirling's approximation says n! ≈ √(2πn) × (n/e)ⁿ for large n. The error is below 1% for n ≥ 10 and below 0.1% for n ≥ 100, so it is essentially exact for any application where you do not need every digit. The log version, log(n!) ≈ n log n − n + 0.5 log(2πn), is the one you actually use in practice because the raw exponential overflows just as fast as n! itself does — but the logarithm does not. Statistical mechanics, information theory, and the saddle-point method in complex analysis all rely on the log form to estimate quantities like the entropy of a system, the asymptotic behavior of binomial coefficients, and the central limit theorem. James Stirling published this in his 1730 Methodus Differentialis; a more precise version was actually found earlier by de Moivre. Refining it to higher accuracy gives the Stirling series, an asymptotic expansion useful in numerical analysis.

All three count arrangements, but they differ in what they consider distinct. Factorial n! counts the number of orderings of n distinct objects — ABCDE has 5! = 120 orderings. Permutation P(n,k) = n! / (n−k)! counts ordered arrangements of k objects chosen from n — P(5,2) = 5!/3! = 20 ordered pairs from 5 items, where AB and BA are counted separately. Combination C(n,k) = n! / (k! × (n−k)!) counts unordered selections of k objects from n — C(5,2) = 10 because AB and BA are now the same. Quick rule of thumb: if order matters, use a permutation; if order does not matter, use a combination. Factorial is the special case where k = n. All three reduce to clean factorial expressions, which is why the factorial calculator is the foundation for all of combinatorics.

Yes — they are defined by the gamma function Γ, which extends the factorial to almost all real and complex numbers. The exact relationship is n! = Γ(n+1), so Γ(1) = 0! = 1, Γ(2) = 1! = 1, Γ(3) = 2! = 2, and so on. For non-integer arguments, you get useful values like Γ(0.5) = √π, which is equivalent to saying (−0.5)! = √π ≈ 1.7725. The half-integer values appear all over physics — the volume of an n-dimensional sphere, the chi-squared distribution, the normalization of the Maxwell-Boltzmann velocity distribution. Negative integers, however, are still undefined: Γ has poles at 0, −1, −2, ..., so (−1)!, (−2)!, etc. are infinite. This calculator returns an error for negative integer input rather than producing a misleading value. If you need Γ values, a dedicated gamma-function tool or a programming language with a tgamma routine is the right tool.

Trailing zeros in n! come from factors of 10 in the product, and each 10 needs one 2 and one 5. The supply of 2s in n! always exceeds the supply of 5s, so the count of trailing zeros equals the total number of 5s in the factorization of n!. Legendre's formula gives this exactly: Z(n) = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + ⌊n/625⌋ + ... until the terms become zero. Example: 100! has ⌊100/5⌋ + ⌊100/25⌋ = 20 + 4 = 24 trailing zeros; 1000! has 200 + 40 + 8 + 1 = 249 trailing zeros. This is a classic competition-math problem, and Legendre's identity gives the answer in O(log n) time — far faster than computing the factorial itself. The same technique works in any base: for base b, count the multiplicity of each prime factor of b in n! and take the minimum after scaling.

Iterative is almost always better for n!. The recursive definition n! = n × (n−1)! reads naturally and is the textbook example for teaching recursion, but in practice it allocates one stack frame per integer down to the base case. JavaScript engines typically have stack limits around 10,000 to 100,000 frames before throwing RangeError: Maximum call stack size exceeded, and Python defaults to 1,000. An iterative loop — for (let i = 2, r = 1n; i <= n; i++) r *= BigInt(i) — uses constant stack and runs faster because there is no function-call overhead per step. Some languages (Scheme, some functional Schemes, Scala in special cases) implement tail-call optimization and can compile a properly written recursive factorial down to a loop, but JavaScript and Python do not. For learning, write the recursive version once to feel the structure; for production code or browser-side calculation like this calculator, use the loop.

In more places than people expect. (1) Probability: birthday paradox, poker hand counts, lottery odds — all built on combinations, which are factorial ratios. (2) Statistics: binomial and multinomial distributions, chi-squared and gamma distributions, Stirling-based normal approximations to discrete laws. (3) Calculus: every Taylor series — sin, cos, e^x, log(1+x) — has n! in its denominator. The factorial in the denominator is what makes the series converge faster than the polynomial grows in the numerator. (4) Physics: partition functions in statistical mechanics, path counting in quantum mechanics, scattering cross-sections. (5) Computer science: counting algorithms, average-case analysis of sorting (n! permutations on n elements), and FFT derivations. (6) Daily life: anagram counts ("how many ways to arrange the letters in MISSISSIPPI?" uses 11! divided by repeated-letter factorials), seating-chart arrangements, password strength estimates.
Factorial Calculator — Free factorial calculator for n! up to 170. Step-by-step results, BigInt support, Stirling approximation, permutations a
Factorial Calculator