Audited 26 Jul 2026·Last updated 28 Oct 2026·6 citations·Tier 1·0 uses

Factorial Calculator

Find n! for any whole number from 0 to 170, plus how many digits it has and its natural log ln(n!). Covers why 0! = 1 and how Stirling's formula works.

Factorial Calculator

Non-negative integer with 0 ≤ n ≤ 170. The upper bound 170 is the IEEE 754 double-precision overflow boundary: 170! ≈ 7.257 × 10³⁰⁶ fits inside Number.MAX_VALUE ≈ 1.798 × 10³⁰⁸, but 171! ≈ 1.241 × 10³⁰⁹ overflows to Infinity. By convention 0! = 1 (the empty product).
n! (factorial)
120
n! — the product of every whole number from 1 to n, with 0! = 1; shown in full up to 17! and as four significant figures times a power of ten from 18! upward.
Number of decimal digits in n!
3
ln(n!) — natural log of n!
4.7875

Background.

Ten people can stand in a queue in 3,628,800 different orders, which happens to be exactly the number of seconds in six weeks. That figure is 10!, read "ten factorial": 10 × 9 × 8 × … × 2 × 1. Whoever goes first can be any of the ten, the second any of the nine who are left, and so on down to the last person, who gets no choice at all. Multiplying the choices together is all a factorial is.

Factorials grow faster than almost anything else in everyday arithmetic. 5! is 120, 10! passes three and a half million, 20! is 2,432,902,008,176,640,000, and 52!, the number of ways to order a standard pack of cards, is about 8.066 × 10⁶⁷. Going from 10 to 20 multiplies the answer by roughly 670 billion. That speed is why factorials turn up in the denominators of probability formulas, binomial coefficients and the series used to compute eˣ, sine and cosine: they shrink terms faster than any power can inflate them.

Enter a whole number from 0 to 170 and you get three results: n! itself, the number of decimal digits it has, and its natural logarithm, ln(n!). The second and third exist because the first becomes unwieldy quickly. From 18! upward the value is shown in scientific notation to four significant figures, so the digit count gives the full size at a glance, and ln(n!) is the form statisticians actually work with when factorials sit inside a likelihood.

The ceiling of 170 has a reason. 170! is about 7.257 × 10³⁰⁶, while 171! is about 1.241 × 10³⁰⁹, beyond the largest value (about 1.798 × 10³⁰⁸) that standard double-precision floating point can hold. That is the number format behind spreadsheets and most programming languages, which is why Excel's FACT function also gives up at 171. Fractions and negative numbers are refused too: as a product, the factorial exists only for non-negative integers, and stretching it to other values needs the gamma function.

What is factorial calculator?

For a non-negative integer n, the factorial n! is the product of every positive integer from 1 up to n. For n = 0 through 10 the values run 1, 1, 2, 6, 24, 120, 720, 5,040, 40,320, 362,880 and 3,628,800. Each term is the previous one multiplied by n, so n! = n × (n − 1)!, and that rule plus the starting value 0! = 1 defines the entire sequence. In counting problems n! is the number of ways to arrange n distinct objects in a row, which is why it is also called the number of permutations of n items. Setting 0! = 1 is not a fudge: a product of no numbers equals 1 for the same reason a sum of no numbers equals 0, and there is exactly one way to arrange nothing. Outside the integers the factorial is carried on by the gamma function, which satisfies Γ(n + 1) = n! at every whole number.

How to use this calculator.

  1. Type a whole number from 0 to 170 into Integer n. If your real question is a ratio such as 52! ÷ (5! × 47!), you seldom need each factorial on its own; a permutation and combination calculator cancels the shared factors first, which is far more accurate than dividing two large numbers that have already been cut to four significant figures.
  2. Read n! in the first result. Up to 17! (355,687,428,096,000) every digit is printed; from 18! on, the value appears as four significant figures times a power of ten, so 20! shows as 2.433 × 10¹⁸.
  3. Use the digit count to judge size, for instance to decide whether a value fits a database column: 25! has 26 digits, 100! has 158 and 170! has 307. To see every digit, use a language with unlimited-size integers, such as Python's math.factorial, which prints them all.
  4. Take ln(n!) when the factorial is one piece of a bigger formula. Work in logarithms — ln C(n, k) = ln n! − ln k! − ln (n − k)! — and convert back with eˣ only at the end, so no intermediate value ever overflows.

The formula.

n! = n × (n−1) × (n−2) × ⋯ × 1

The definition is a running product, n! = 1 × 2 × 3 × … × n with 0! = 1, and the calculator multiplies it out in full using whole-number arithmetic, so nothing is approximated before the finished value is displayed.

The digit count comes from logarithms. A positive whole number N has ⌊log₁₀ N⌋ + 1 digits: log₁₀ 120 ≈ 2.0792, the floor is 2, add one and you get 3. Since log₁₀(n!) = ln(n!) ÷ ln 10, the digit count is read off the third result.

That third result, ln(n!), is found in one of two ways. Up to n = 100 it is the plain sum ln 2 + ln 3 + … + ln n. Above 100 it uses Stirling's series, ln(n!) ≈ n ln n − n + ½ ln(2πn) + 1/(12n) − 1/(360n³), as given in Abramowitz and Stegun §6.1 and the NIST Digital Library of Mathematical Functions §5.11. With those two correction terms the series and the direct sum agree to within about 8 × 10⁻¹⁶ in relative terms everywhere from n = 90 to 170, which is at the limit of what a double-precision number can resolve, and the digit count matches the true length of n! for every n from 0 to 170.

Where does Stirling's formula come from? ln(n!) is a sum of logarithms, and that sum is close to the area under the curve ln x from 1 to n, which integrates to n ln n − n + 1. The ½ ln(2πn) term and the small corrections account for the gap between the staircase of the sum and the smooth curve. Exponentiating the first three terms gives the familiar n! ≈ √(2πn) · (n/e)ⁿ. On its own that short form runs low by roughly 1/(12n) as a fraction: about 1.65% at n = 5, 0.83% at n = 10 and 0.083% at n = 100. The series is asymptotic rather than convergent, so adding ever more terms does not help indefinitely at a fixed n, but two corrections are plenty in the range used here.

A worked example.

Example

Take n = 5, the default. Build the product one factor at a time: 1 × 2 = 2, then 2 × 3 = 6, then 6 × 4 = 24, then 24 × 5 = 120. So 5! = 120, and five books can stand on a shelf in 120 different orders — 24 of them with any particular book on the left, because once that book is fixed the other four can be arranged in 4! = 24 ways. For the digit count, log₁₀ 120 ≈ 2.0792; the whole-number part is 2, and adding one gives 3 digits, which is plainly right for 120. For the natural log, ln 120 = 4.7875. The same value comes from adding ln 2 + ln 3 + ln 4 + ln 5 ≈ 0.6931 + 1.0986 + 1.3863 + 1.6094, because the logarithm of a product is the sum of the logarithms of its factors. At n = 100 the three results become 9.333 × 10¹⁵⁷, 158 digits and 363.7394. The 158 follows from the logarithm: 363.7394 ÷ ln 10 (2.302585) ≈ 157.97, whose whole-number part is 157, plus one. That is the method to use whenever the factorial itself is too long to count by eye.

extend To Realsno
n5

Frequently asked questions.

Why is 0! defined as 1 rather than 0?
Three separate arguments land on 1. A product with no factors is the multiplicative identity, just as an empty sum is 0. The rule n! = n × (n − 1)! at n = 1 gives 1 = 1 × 0!, which forces 0! = 1. And there is exactly one way to arrange zero objects: do nothing. The choice also makes C(n, 0) = n! ÷ (0! × n!) = 1 work without a special case.
Why can't I enter a number larger than 170?
Because 171! is about 1.241 × 10³⁰⁹, past the roughly 1.798 × 10³⁰⁸ ceiling of double-precision numbers, so it could not be shown as a finite value. Many handheld calculators stop much earlier, at 69!, because they display nothing above 10¹⁰⁰. For larger n, Python's math.factorial handles integers of any length; for size alone, Stirling's series gives ln(1000!) ≈ 5,912.1282, so 1000! has 2,568 digits.
How many zeros are at the end of 100!?
Twenty-four. Each trailing zero needs a factor of 10, that is one 2 and one 5, and fives are the scarcer of the two. Count them by Legendre's method: 100 ÷ 5 = 20 multiples of 5, plus 100 ÷ 25 = 4 multiples of 25 that each contribute a second five. The same count gives 6 zeros for 25! and 41 for 170!.
My program prints a wrong or negative number for 13! or 21!. What went wrong?
Integer overflow. A 32-bit signed integer tops out at 2,147,483,647, so 12! = 479,001,600 fits but 13! = 6,227,020,800 does not. A 64-bit signed integer reaches about 9.22 × 10¹⁸, which holds 20! but not 21! = 51,090,942,171,709,440,000. Many languages wrap around silently instead of raising an error, which produces garbage or negative values.
Does a fraction like (1/2)! have a value?
Yes, through the gamma function, Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt, which satisfies Γ(n + 1) = n! at whole numbers. It gives (1/2)! = Γ(3/2) = √π/2 ≈ 0.8862 and (−1/2)! = √π ≈ 1.7725. Negative integers have no value because gamma has poles there. Fractions are refused here, so use a gamma-function calculator for them.
How do factorials give the number of poker hands or podium finishes?
Ordered selections use P(n, r) = n! ÷ (n − r)!, so gold, silver and bronze among 10 runners can go 10! ÷ 7! = 720 ways. Unordered selections divide out the r! internal orderings: C(n, r) = n! ÷ (r! × (n − r)!). Five cards from 52 gives C(52, 5) = 2,598,960 possible poker hands, a count far smaller than 52! because order inside a hand does not matter.
Is n!! the factorial of a factorial?
No. The double factorial n!! multiplies every other integer down from n: 7!! = 7 × 5 × 3 × 1 = 105 and 8!! = 8 × 6 × 4 × 2 = 384. The factorial of a factorial is written (n!)!, and the two differ enormously: 3!! is 3, while (3!)! = 6! = 720. Double factorials appear in the moments of the normal distribution and in half-integer gamma values.
How close is Stirling's approximation, and where is it used?
The short form √(2πn)(n/e)ⁿ falls short by about 1/(12n): roughly 1.65% at n = 5, 0.83% at n = 10 and 0.083% at n = 100. Adding the 1/(12n) and 1/(360n³) terms in log form makes it accurate to the last digit of a double above n = 100. Physicists use the cruder ln N! ≈ N ln N − N when counting arrangements of huge numbers of particles.
When is ln(n!) more useful than n! itself?
Whenever factorials appear inside a probability. ln C(52, 5) = ln 52! − ln 5! − ln 47! ≈ 156.3608 − 4.7875 − 136.8027 = 14.7706, and exponentiating that gives back 2,598,960 without ever handling a 68-digit number. Statistical software works this way through log-gamma functions such as lgamma in C or gammaln in SciPy, especially for Poisson and binomial likelihoods.
Do factorials have anything to do with prime numbers?
Wilson's theorem says p is prime exactly when (p − 1)! leaves remainder p − 1 on division by p: 6! = 720 = 7 × 102 + 6. It is too slow to be a practical primality test. Factorials also prove that prime gaps can be as long as you like, since n! + 2, n! + 3, …, n! + n are all composite: n! + k is divisible by k.

References& sources.

  1. [1]Knuth, Donald E. The Art of Computer Programming, Volume 1: Fundamental Algorithms, 3rd edition. Addison-Wesley, 1997. §1.2.5 ('Permutations and Factorials') contains the canonical definition n! = 1·2·…·n with 0! = 1 by the empty-product convention, the standard recursion, and the integer-precision considerations for large n. §1.2.11.2 ('Stirling's Approximation') gives the asymptotic series with Bernoulli-number coefficients used by this calculator.
  2. [2]Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 6th edition, revised by Heath-Brown and Silverman. Oxford University Press, 2008. §1.2 (and the surrounding sections of Chapter I) establishes the factorial convention 0! = 1, the recursion n! = n·(n−1)!, the binomial coefficient identities derived from it, and the elementary number-theoretic properties (Wilson's theorem, divisibility of factorials by primes).
  3. [3]NIST Digital Library of Mathematical Functions, Chapter 5 ('Gamma Function'), §5.2 (Definition) and §5.11 (Asymptotic Expansions). Authoritative reference definitions of Γ(z), the integer relation Γ(n+1) = n!, the Stirling asymptotic series ln(n!) ~ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + …, and the analytic continuation to the complex plane.
  4. [4]Abramowitz, M. and Stegun, I. A. (eds.). Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. National Bureau of Standards Applied Mathematics Series 55, 10th printing, 1972. §6.1 ('Gamma Function') contains the classical Stirling asymptotic series 6.1.41, half-integer factorial values, and the recursion identities — the canonical numerical-analysis reference for factorials and the gamma function.
  5. [5]Stirling, James. Methodus Differentialis: sive Tractatus de Summatione et Interpolatione Serierum Infinitarum. London, 1730. The original publication of Stirling's approximation in its asymptotic series form. Modern English translation and commentary in Tweddle, I. James Stirling's Methodus Differentialis, Springer, 2003.
  6. [6]Graham, R. L., Knuth, D. E., and Patashnik, O. Concrete Mathematics: A Foundation for Computer Science, 2nd edition. Addison-Wesley, 1994. Chapter 5 ('Binomial Coefficients') and §6.1 ('Stirling Numbers') give the modern computer-science treatment of factorial identities, hypergeometric-series perspectives, and the snake-oil method for proving factorial-ratio identities.

How this page was produced

Published by
Quanta Calculator
Primary sources
6 cited below
Method
n! = n × (n−1) × (n−2) × ⋯ × 1
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon