Factorial Calculator — Compute n! with Steps — Free Online Calculator
Calculate the factorial of any number from 0 to 170. Shows the step-by-step multiplication, digit count, and trailing zeros.
See it worked out
Example — Number (n) 5:
Factorial (5!)
120
Step-by-Step Calculation
5 × 4 × 3 × 2 × 1 = 120
Number of Digits
3
Trailing Zeros
1
The formula
n! = n x (n-1) x (n-2) x ... x 1
- n!
- Factorial of n
- n
- Input Number
- d
- Digit Count
- z
- Trailing Zeros
Worked example — Number (n) 5
Factorial (5!) = 120
How Factorial Calculator Works
n! = n x (n-1) x (n-2) x ... x 1
The factorial of a non-negative integer n, denoted n!, is the product of all positive integers less than or equal to n. By definition, 0! = 1. Factorials grow extremely fast — 10! = 3,628,800 and 20! is already over 2.4 quintillion. The factorial function is defined recursively as n! = n x (n-1)! with the base case 0! = 1. For n = 0, the empty product is defined as 1, which is consistent with combinatorial formulas and infinite series.
- n!
- Factorial of n — The product of all positive integers from 1 to n. Pronounced "n factorial." For n = 0, the result is defined as 1.
- n
- Input Number — A non-negative integer whose factorial is being computed. Must be between 0 and 170 for JavaScript to maintain precision.
- d
- Digit Count — The number of decimal digits in n!. For large n, this can be computed approximately using Kamenetsky's formula: d = floor(n * log10(n/e) + log10(2*pi*n)/2) + 1.
- z
- Trailing Zeros — The number of zeros at the end of n! in decimal representation. Determined by counting factors of 5 in the prime factorization of n!.
How to Use
- Enter a non-negative integer n (from 0 to 170) in the input field.
- View the factorial result displayed with comma separators for readability.
- Read the step-by-step multiplication showing how each term contributes to the final product.
- Check the digit count to understand how large the factorial result is.
- See the trailing zeros count, which reveals how many times 10 divides the factorial.
Quick Reference
| 0! | 1 (by definition) |
| 1! | 1 |
| 5! | 120 |
| 10! | 3,628,800 |
Common Uses
- •Permutations and combinations: n! is the number of ways to arrange n distinct objects, and appears in nPr and nCr formulas.
- •Probability and statistics: factorial appears in binomial coefficients, Poisson distributions, and Bayesian inference.
- •Calculus: factorials appear in Taylor series expansions for e^x, sin(x), cos(x), and many other functions.
- •Number theory: factorials are used in Wilson's theorem for primality testing and studying prime distributions.
- •Computer science: factorial growth models the worst-case complexity of certain algorithms and appears in asymptotic analysis.
Understanding the Result
The factorial function is one of the most important functions in mathematics, appearing throughout combinatorics, algebra, analysis, and number theory. For a non-negative integer n, the factorial n! is defined as the product of all positive integers from 1 to n: n! = n x (n-1) x (n-2) x ... x 2 x 1. The special case 0! = 1 is defined for consistency — it makes combinatorial formulas work (there is exactly one way to arrange zero objects, and the binomial coefficient (0 choose 0) = 1). Factorials grow at an astonishing rate. While 5! = 120 is modest, 10! = 3,628,800, 15! = 1,307,674,368,000, and 20! = 2,432,902,008,176,640,000. By 170!, the value exceeds 10^306, which is the limit of JavaScript's 64-bit floating-point precision (Number.MAX_VALUE is about 1.79 x 10^308). Beyond 170, the factorial overflows to Infinity. The number of trailing zeros in n! can be found without computing the full factorial: count how many factors of 5 appear in the numbers 1 through n (since factors of 2 are always more abundant). This is computed as floor(n/5) + floor(n/25) + floor(n/125) + ... For example, 25! has 6 trailing zeros: floor(25/5) = 5 from multiples of 5, plus floor(25/25) = 1 from the extra factor of 5 in 25 itself. The digit count of n! can be approximated using Stirling's approximation: n! ~ sqrt(2*pi*n) x (n/e)^n, which gives ln(n!) ~ n*ln(n) - n + 0.5*ln(2*pi*n). Taking log10 gives the number of decimal digits.
Frequently Asked Questions
- Why is 0! defined as 1?
- 0! = 1 by definition, and there are several good reasons for this. Mathematically, n! = n x (n-1)!, so for n = 1, we have 1! = 1 x 0!, which gives 1 = 1 x 0!, so 0! must equal 1. Combinatorially, there is exactly one way to arrange zero objects (the empty arrangement). The binomial coefficient formula n choose k = n! / (k! x (n-k)!) also works when k = 0 or k = n only if 0! = 1.
- What is the largest factorial my calculator can compute?
- This calculator can compute factorials up to 170! using JavaScript's 64-bit floating-point numbers. 170! is approximately 7.26 x 10^306, just below the maximum representable value of about 1.79 x 10^308. For n > 170, the result overflows to Infinity and cannot be displayed accurately. For exact arithmetic on larger numbers, you would need arbitrary-precision libraries or specialized software.
- How do you calculate trailing zeros without computing the whole factorial?
- Trailing zeros come from factors of 10, which are produced by pairs of factors 2 and 5. Since factors of 2 are much more common than factors of 5, the number of trailing zeros equals the total number of factors of 5 in the numbers from 1 to n. This is computed as floor(n/5) + floor(n/25) + floor(n/125) + ... because each multiple of 5 contributes one factor of 5, each multiple of 25 contributes an additional factor, and so on. For 100!, this gives floor(100/5) + floor(100/25) + floor(100/125) = 20 + 4 + 0 = 24 trailing zeros.
- What is Stirling's approximation?
- Stirling's approximation is a formula for estimating factorials: n! ~ sqrt(2*pi*n) x (n/e)^n. It becomes more accurate as n increases. The relative error is about 1/(12n). For n = 10, the approximation gives about 3,598,695 compared to the exact 3,628,800 (about 0.8% error). For n = 100, the error drops to about 0.08%. Stirling's approximation is widely used in statistical mechanics, probability theory, and asymptotic analysis.
Cite this calculator
TheCalcUniverse. "Factorial Calculator — Compute n! with Steps — Free Online Calculator." TheCalcUniverse, 2026, https://thecalcuniverse.com/math/factorial-calculator/. Accessed July 24, 2026.
Embed this calculator on your site
You may also like
-
Permutations & Combos
Calculate permutations (nPr) and combinations (nCr) with step-by-step factorial breakdown. Toggle between orde…
-
Probability
Compute joint (A∩B), union (A∪B), conditional P(A|B), and complement probabilities for independent or mutually…
-
Prime Checker
Check if any number is prime using trial division. Find its prime factorization, count all divisors, and see s…
-
Number Sequences
Identify arithmetic, geometric, and Fibonacci sequences. Find common difference, common ratio, nth-term formul…