Last verified · v1.0
Calculator · math
Factorial Calculator
Calculate the factorial of any integer from 0 to 170 instantly. Get the exact n! value with formula explanation and step-by-step examples.
Inputs
Factorial (n!)
—
Explain my result
Get a plain-English breakdown of your result with practical next steps.
The formula
How the
result is
computed.
What Is a Factorial?
The factorial of a non-negative integer n, written as n!, is the product of every positive integer from 1 up to and including n. The operation appears across combinatorics, probability theory, calculus, and computer science, making it one of the most fundamental functions in all of mathematics.
Factorial Formula
The standard definition states:
n! = n × (n−1) × (n−2) × … × 2 × 1
By mathematical convention, the zero factorial equals:
0! = 1
This definition is not arbitrary. Without it, combinatorial formulas such as the binomial coefficient C(n, 0) = n! / (0! × n!) would be undefined, breaking fundamental counting theory.
Step-by-Step Examples
- 1! = 1
- 2! = 2 × 1 = 2
- 3! = 3 × 2 × 1 = 6
- 4! = 4 × 3 × 2 × 1 = 24
- 5! = 5 × 4 × 3 × 2 × 1 = 120
- 10! = 3,628,800
- 20! = 2,432,902,008,176,640,000
Factorials grow at a superexponential rate. By n = 100, the result contains 158 digits. At n = 170, the value reaches approximately 7.26 × 10306—near the upper boundary of JavaScript's 64-bit IEEE 754 floating-point representation. Inputs above 170 produce numeric overflow to Infinity, which is why this calculator caps n at 170.
Variables
- n — a non-negative integer (0, 1, 2, …, 170). Factorial is undefined for negative integers and non-integer values under the standard definition.
Real-World Applications
Permutations and Ordered Arrangements
The number of ordered arrangements of n distinct objects equals n!. Six runners in a race can finish in 6! = 720 possible orders. This principle drives scheduling algorithms, tournament bracket generation, and cryptographic key-space analysis across fields from software engineering to operations research.
Combinations and Probability
The binomial coefficient C(n, k) = n! / (k! × (n−k)!) counts the number of ways to choose k items from n without regard to order. The total number of 5-card poker hands from a standard 52-card deck equals C(52, 5) = 52! / (5! × 47!) = 2,598,960. Factorial-based probability underpins risk analysis, genetics, and statistical quality control.
Experimental Design and Statistics
According to the NIST Engineering Statistics Handbook, full factorial experiments test every possible combination of factor levels. With 3 factors each set at 2 levels, the design requires 23 = 8 experimental runs—a direct application of factorial enumeration in manufacturing process optimization and scientific research.
Taylor Series and Calculus
Factorials serve as denominators in Taylor series expansions. The natural exponential function expands as ex = 1 + x + x2/2! + x3/3! + … and the series for sin(x) and cos(x) follow the same factorial pattern. These series are foundational in engineering simulation, signal processing, and numerical computing.
Statistical Mechanics and Physics
As described in the University of Massachusetts Physics 131 open textbook, factorials quantify the number of microstates in a physical system. Boltzmann's entropy formula S = kB ln(Ω) relies on factorial-based counting of Ω microstates, linking n! directly to thermodynamics and information theory.
Computational Limits and Stirling's Approximation
For very large n, exact factorial computation becomes impractical. Stirling's approximation provides a powerful estimate: ln(n!) ≈ n ln(n) − n. For n = 100, this formula produces an error of less than 1% compared to the exact 158-digit value. Scientific computing libraries and statistical software rely on log-factorial approximations for Bayesian inference, machine learning, and large-scale physics simulations where exact values would overflow any standard numeric type.
Algorithm and Implementation
Computing factorials can be implemented iteratively or recursively. The iterative approach multiplies successive integers from 1 to n, maintaining accuracy by avoiding deep call stacks. Recursive implementations, while elegant, suffer from stack overflow on large inputs unless memoization caches previously computed values. For production calculators handling values up to 170, iterative computation with careful numeric handling provides optimal performance and reliability. Modern JavaScript engines use 64-bit IEEE 754 double-precision floats, necessitating the 170-value ceiling to prevent overflow and ensure consistent, accurate results across all supported inputs.
Reference