Factorial Calculator
Factorial of any number up to 170.
Formula
n! = n×(n-1)×...×1
Example
5! = 120.
Embed this calculator on your site
Add this free calculator to your own website with one line of code. The embedded version is responsive, ad-free, and includes a small attribution link back to CalcNest AI.
<iframe src="https://calcnestai.com/embed/factorial-calculator.html" width="100%" height="700" frameborder="0" style="border: 1px solid #e5e5e5; border-radius: 12px; max-width: 720px;" loading="lazy" title="Factorial Calculator — Free Tool by CalcNest AI"></iframe>
Understanding the Factorial Calculator
A factorial calculator multiplies every integer from 1 up to n. Factorials grow faster than exponentials, which is why the calculator stops at 170: beyond that the result exceeds what double-precision floating point can represent at all.
How it actually works
Enter a whole number from 0 to 170. The calculator multiplies successively from 2 upward, showing an exact integer up to 20 and scientific notation beyond. Ten factorial is 3,628,800.
| n | n! |
|---|---|
| 10 | 3.6 million |
| 20 | 2.4 × 10¹⁸ |
| 70 | 1.2 × 10¹⁰⁰ |
| 170 | 7.3 × 10³⁰⁶ |
The deeper context most people miss
Twenty factorial is roughly the number of grains in a large sand dune, and 52 factorial, the number of orderings of a shuffled deck, is around 8 × 10⁶⁷. That figure exceeds the number of atoms in the observable galaxy, which is why any well-shuffled deck has almost certainly never existed in that order before.
Why 0! equals 1
This looks like a convention chosen for convenience and is better understood as forced by consistency. The recursive definition states that n! equals n times (n−1)!, so rearranging gives (n−1)! equals n! divided by n, and setting n to 1 gives 0! equals 1! divided by 1, which is 1. The combinatorial argument is more satisfying: n! counts the number of ways to arrange n distinct objects, and there is exactly one way to arrange zero objects, namely the empty arrangement, so 0! is 1 rather than 0. The same logic underlies the empty product convention, where a product over no terms is 1 just as a sum over no terms is 0, because 1 is the multiplicative identity. Any other value breaks things: the binomial coefficient formula, the Taylor series where the first term divides by 0!, and the combinatorial identities all require it. The gamma function, which extends factorials to non-integer and complex arguments, confirms it independently, with gamma of 1 equalling 1 and the relationship being that n! equals gamma of n+1. That offset by one is an inconvenience of historical notation rather than anything meaningful. The gamma function is where factorials become genuinely interesting, since it allows factorials of fractions, with the factorial of one half being the square root of π over two, which is a startling appearance of π in a context that has nothing visibly to do with circles.
A worked example: where 170 comes from
The limit is set by the IEEE 754 double-precision format, which represents numbers up to approximately 1.8 × 10³⁰⁸. One hundred and seventy factorial is roughly 7.3 × 10³⁰⁶ and fits; 171 factorial exceeds the range and overflows to infinity, which is why the calculator declines rather than returning a meaningless result. A separate and earlier limit affects exactness: doubles represent integers exactly only up to 2⁵³, which is about 9 × 10¹⁵, so factorials above 18 are already inexact even though they display without obvious error. This matters because a calculator showing 21! as a long integer would be showing digits that are wrong at the end, which is why scientific notation is used above 20 rather than a spuriously precise integer. Computing large factorials exactly requires arbitrary-precision arithmetic, available in Python natively and through libraries in most languages, and the result grows large quickly: 1000 factorial has 2,568 digits. For most practical purposes the exact value is not needed, and Stirling's approximation gives an excellent estimate as n! approximately equal to the square root of 2πn times n over e to the power n, with relative error falling as n grows. That approximation is what makes factorials tractable in analysis, and it appears throughout statistical mechanics and information theory for exactly that reason.
Deciding when you actually need a factorial
Factorials appear wherever ordering or selection matters. Permutations count arrangements where order matters, given by n! for all objects or n!/(n−r)! for r of them. Combinations count selections where order does not, given by the binomial coefficient n!/(r!(n−r)!), and the distinction between the two is the single most common source of error in introductory probability: the number of ways to pick three people for identical prizes differs from the number of ways to award gold, silver, and bronze by a factor of 3!. Factorials appear in the binomial and Poisson distributions, in the denominators of Taylor series, in the number of ways to partition sets, and throughout combinatorics. They appear in algorithm analysis, where a problem requiring examination of all permutations has factorial complexity, which is worse than exponential and makes brute force infeasible beyond very small inputs, and the travelling salesman problem is the standard illustration. In practice, when a calculation involves large factorials divided by other large factorials, computing them separately overflows unnecessarily while cancelling terms first keeps everything manageable, which is why binomial coefficients should be computed by multiplying and dividing incrementally rather than by evaluating three factorials and combining them.
Stirling's approximation and why it matters
Computing n! directly requires n multiplications and produces an enormous number, which is impractical for the large values that appear in statistical mechanics and information theory. Stirling's approximation replaces it with a closed-form expression that is easy to evaluate and increasingly accurate as n grows: n! is approximately the square root of 2πn multiplied by n over e raised to the power n. The relative error is about 1 over 12n, so it is under 1% by n equals 9 and negligible by the values where it is actually used. More refined versions add correction terms. Taking logarithms gives an even more useful form, since log n! is approximately n log n minus n, and this appears constantly: in the derivation of the Boltzmann entropy formula, where counting microstates involves factorials of Avogadro-scale numbers that could never be computed directly; in information theory; and in algorithm analysis, where the log n! result establishes that comparison-based sorting requires at least n log n comparisons, which is a genuine lower bound rather than a property of any particular algorithm. That last result is a good example of factorials producing a practical conclusion: because there are n! possible orderings and each comparison distinguishes at most two branches, no comparison sort can do better, which is why quicksort and mergesort are asymptotically optimal.
Variations: double factorials, gamma, and related functions
The double factorial n!! multiplies every other integer down from n, so 7!! is 7×5×3×1, and it appears in integrals of powers of trigonometric functions and in some combinatorial identities. It is not the factorial of a factorial, which is a common misreading. The gamma function extends factorials to real and complex arguments and is the standard generalisation, appearing throughout analysis and in the gamma, beta, and chi-squared distributions. The beta function relates to it directly. Subfactorials count derangements, meaning permutations where no element remains in its original position, which answers the classic problem of how many ways letters can be placed in envelopes with none matching, and the proportion converges to 1 over e. Falling and rising factorials, also called Pochhammer symbols, appear in hypergeometric functions and in finite difference calculus. Primorials multiply primes rather than all integers. Superfactorials and hyperfactorials extend the idea further and are mostly curiosities. For computation, most languages provide gamma or log-gamma functions, and using log-gamma to work with logarithms of factorials avoids overflow entirely, which is the standard technique in statistical computing.
Working with factorials
Use 0! equals 1, which follows from the recursive definition and from there being exactly one arrangement of zero objects, rather than being an arbitrary convention. Note that double-precision factorials are exact only to 18 and overflow above 170, so use arbitrary-precision arithmetic where exact large values are needed. Distinguish permutations from combinations, since order mattering or not changes the answer by a factor of r! and it is the most common error in introductory probability. Cancel terms before computing when a formula divides factorials, since evaluating each separately overflows unnecessarily while incremental multiplication and division stays manageable. Use Stirling's approximation for large n, which is accurate to under 1% by n equals 9 and makes analysis tractable. Work with log-gamma rather than gamma in statistical computing, which avoids overflow entirely. Read n!! as a double factorial multiplying alternate integers rather than the factorial of a factorial. And recognise factorial complexity in algorithms as infeasible beyond small inputs, since it grows faster than exponential.
What people get wrong
- Treating 0! equals 1 as an arbitrary convention, when it follows from the recursive definition and from there being exactly one way to arrange nothing.
- Using permutations where combinations are needed, which overcounts by a factor of r! and is the most frequent error in introductory probability problems.
- Computing each factorial separately in a formula that divides them, which overflows unnecessarily where cancelling terms first keeps every intermediate value manageable.
- Trusting a factorial above 18 in double precision, where integers are no longer represented exactly even though the display shows no sign of error.
Where the math comes from
n! = n × (n−1) × … × 2 × 1, with 0! defined as 1. The calculator multiplies successively from 2 to n. Double-precision floating point represents integers exactly only to 2⁵³, so results above 18! are inexact, and the maximum representable value of about 1.8 × 10³⁰⁸ means 171! overflows to infinity, which is why 170 is the limit.
Questions and answers
How do I check my answer?
Plug the answer back into the original equation. If both sides match, the answer is correct. This works for any algebraic problem.
Can the calculator handle complex roots?
Most basic calculators handle real roots only. Complex roots (when discriminant is negative for quadratics) require a complex-number-aware calculator.
What if the equation has no solution?
Some equations have no real solutions. The calculator should indicate this rather than returning nonsense. If it does not, try simplifying the equation first.
How do I solve systems of equations?
Substitution, elimination, or matrix methods. Two-equation, two-unknown systems are simplest; larger systems need matrix calculators.
Is there one method that always works?
For polynomials up to degree 4, yes - the quadratic, cubic, and quartic formulas. Degree 5+ generally requires numerical methods. For most real-world problems, factoring, formula, or graphing handles everything.
Why is 0! equal to 1?
Because the recursive definition requires it: (n−1)! equals n! divided by n, so 0! equals 1! divided by 1. Combinatorially there is exactly one way to arrange zero objects, the empty arrangement, and any other value breaks binomial coefficients and Taylor series.
Why does the calculator stop at 170?
Because 171! exceeds the largest number double-precision floating point can represent, roughly 1.8 × 10³⁰⁸, and overflows to infinity. Exactness fails earlier still, at 18!, since doubles represent integers exactly only up to 2⁵³.
How large is 52 factorial?
Around 8 × 10⁶⁷, the number of possible orderings of a shuffled deck of cards. That exceeds the number of atoms in the observable galaxy, which is why a properly shuffled deck has almost certainly never appeared in that exact order before.
What's the difference between permutations and combinations?
Whether order matters. Permutations count arrangements, given by n!/(n−r)!, while combinations count selections regardless of order, given by n!/(r!(n−r)!). Confusing them overcounts by a factor of r! and is the most common error in introductory probability.
Can you take the factorial of a fraction?
Through the gamma function, which extends factorials to real and complex arguments, with n! equal to gamma of n+1. The factorial of one half is the square root of π over two, which is a surprising appearance of π in a context unrelated to circles.
What is Stirling's approximation?
An estimate giving n! as approximately the square root of 2πn times n over e to the power n, with relative error around 1 over 12n. It's under 1% by n equals 9 and makes factorials tractable in statistical mechanics and algorithm analysis.
What does n!! mean?
The double factorial, multiplying every other integer down from n, so 7!! is 7×5×3×1. It is not the factorial of a factorial, which is a common misreading, and it appears in integrals of trigonometric powers and some combinatorial identities.
Related calculators
Greatest Common Factor · Equation of Circle · Matrix 3x3 Determinant · Matrix Addition · Quadratic Equation