Factorial Calculator
Free factorial calculator: compute n! for any non-negative integer 0 to 170, with digit count, ln(n!), Stirling approximation, and worked examples.
Factorial Calculator
Background.
The Quanta factorial calculator computes n! for any non-negative integer n from 0 to 170 — the full range of factorials that fit inside an IEEE 754 double-precision number. Enter n = 5 and it returns 5! = 120. Enter n = 10 and it returns 10! = 3,628,800. Enter n = 20 and it returns 20! = 2,432,902,008,176,640,000 — twenty factorial, just below the 2⁶³ signed-64-bit-integer ceiling, the largest factorial that fits inside a long. Enter n = 170 and it returns roughly 7.257 × 10³⁰⁶, a 307-digit number that is the very last finite factorial the JavaScript number type can hold before 171! overflows to Infinity.
The factorial function n! = n × (n−1) × (n−2) × … × 2 × 1 is one of the most ubiquitous quantities in mathematics. It counts the number of distinct orderings of n distinguishable objects — five books on a shelf can be arranged in 5! = 120 ways; a 52-card deck has 52! ≈ 8.07 × 10⁶⁷ possible shuffles, more orderings than there are atoms in our galaxy. Factorials power the binomial coefficient C(n,r) = n! / (r!(n−r)!) and therefore every permutation and combination problem in combinatorics, every binomial-theorem expansion, every Pascal-triangle entry. They are the denominators of the Taylor series for the analytic functions of mathematical physics — eˣ = Σ xⁿ/n!, sin x = Σ (−1)ⁿ x²ⁿ⁺¹/(2n+1)!, cos x = Σ (−1)ⁿ x²ⁿ/(2n)! — and therefore underlie every numerical evaluation of the elementary transcendental functions. They define the Poisson distribution P(k; λ) = λᵏ e⁻ᵏ / k! used in queueing theory, reliability engineering, and epidemiology; the gamma distribution; the chi-squared distribution; and the multinomial coefficient n! / (n₁! n₂! … n_k!).
The convention 0! = 1 surprises beginners but is forced by three independent arguments that all point to the same value: the empty product (a product over zero factors is the multiplicative identity 1, by the same convention that makes the empty sum 0); the factorial recursion n! = n × (n−1)! evaluated at n = 1 (forcing 1! = 1 · 0!, so 0! = 1); and combinatorial consistency (there is exactly one way to arrange zero objects — namely doing nothing — so 0! must count one outcome). Hardy and Wright §1.2 and NIST DLMF §5.2 both codify this convention, and it is what makes the binomial coefficient formula C(n, 0) = C(n, n) = 1 emerge from n! / (0! n!) without a special case.
Factorials grow extraordinarily fast — faster than any exponential, slower than any double exponential — a regime mathematicians call super-exponential. The exact growth rate is captured by Stirling's approximation, proved by James Stirling in his 1730 Methodus Differentialis and refined by de Moivre at roughly the same time: n! ≈ √(2πn) · (n/e)ⁿ, with relative error O(1/n). The asymptotic series form ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + … (Abramowitz & Stegun §6.1.41) is so accurate by n = 10 that practical numerics use it everywhere outside the small-n exact-sum regime; the Quanta engine uses it for n > 100 and falls back to the exact log-sum Σ ln(i) for smaller arguments.
To extend the factorial beyond the integers you leave the realm of products and enter the realm of the gamma function. Euler showed in a 1729 letter to Goldbach that the unique smooth function satisfying Γ(1) = 1 and Γ(z+1) = z · Γ(z) for all positive z is Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt — and that this function satisfies Γ(n+1) = n! for every non-negative integer n, agreeing with the factorial wherever both are defined. The gamma function gives a value for (1/2)! = Γ(3/2) = √π/2 ≈ 0.8862, for (−1/2)! = Γ(1/2) = √π, and for every complex argument except the non-positive integers (where it has poles). NIST DLMF Chapter 5 is the authoritative reference.
The Quanta calculator does not yet evaluate the gamma extension — the 'extendToReals' option in the input panel is reserved for a future release and currently rejects non-integer n with an explicit error — but the calculator's documentation below covers the construction of the extension in detail, so you can see exactly what an upgrade would compute. Whatever you arrived to calculate — homework, a Poisson likelihood, the denominator of a Taylor coefficient, the size of a permutation group, the answer to 'how many ways can 10 students line up?', the order of magnitude of 100! for a probability estimate — the calculator above and the explainer below cover every variant of the question with the primary-source citations to back them up.
What is factorial calculator?
The factorial of a non-negative integer n, written n! and read 'n factorial', is the product of all positive integers from 1 up to n: n! = n × (n−1) × (n−2) × … × 2 × 1. The first values are 0! = 1, 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, 7! = 5,040, 8! = 40,320, 9! = 362,880, 10! = 3,628,800. The recursion n! = n × (n−1)! and the base case 0! = 1 together pin the function down on the non-negative integers. The convention 0! = 1 is forced. First, by the empty product: n! is a product of n factors, so 0! is a product of zero factors, and the empty product equals the multiplicative identity 1 by the same convention that gives the empty sum the value 0. Second, by the recursion: n! = n × (n−1)! must hold for n = 1, giving 1! = 1 × 0!, which can only be consistent with 1! = 1 if 0! = 1. Third, by combinatorial consistency: n! counts the number of orderings of n distinguishable items, and there is exactly one ordering of zero items (do nothing), so 0! must equal 1. The same convention makes the binomial coefficient formula C(n, 0) = n!/(0! n!) = 1 work without a special case, and it lets the Taylor series eˣ = Σₙ₌₀^∞ xⁿ/n! begin at n = 0 with x⁰/0! = 1 without an additive correction. The factorial is super-exponential: it grows faster than any function of the form aⁿ for fixed a, because the multiplicative factor at step n is n itself rather than a constant. Concretely, log(n!) is Θ(n log n) by Stirling's formula, while log(aⁿ) = n log a is Θ(n). This is why 100! ≈ 9.33 × 10¹⁵⁷ is a 158-digit number — almost incomprehensibly large compared to any exponential 100ⁿ that has only ~200 digits at the same n. The factorial extends to all real and complex arguments (except the non-positive integers) via the gamma function Γ, which Euler introduced in 1729 and which satisfies Γ(n + 1) = n! for non-negative integers n. NIST DLMF §5.2 gives Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt as the canonical integral definition for Re(z) > 0; the rest of the complex plane is filled in by analytic continuation through the recursion Γ(z + 1) = z · Γ(z). At non-integer real arguments Γ takes unexpected values — Γ(1/2) = √π ≈ 1.7725, so (−1/2)! = √π and (1/2)! = √π/2. The Quanta calculator restricts itself to integer factorials for this Tier 1 release, but every formula on this page extends seamlessly to the gamma function when you need it.
How to use this calculator.
- Enter your non-negative integer n in the input field. Any whole number from 0 up to 170 is accepted. The lower bound is 0 because the factorial is defined for non-negative integers (0! = 1 by convention). The upper bound is 170 because 170! ≈ 7.257 × 10³⁰⁶ is the last factorial that fits inside an IEEE 754 double, and 171! ≈ 1.241 × 10³⁰⁹ overflows the double-precision range to Infinity.
- Leave the 'Extend to real arguments via Γ(n+1)?' toggle on 'No'. The option is reserved for a future release. The current Tier 1 formula computes exact integer factorials only via BigInt multiplication and will reject any non-integer n with an InvalidInputError that names the limitation explicitly.
- Read the primary output — n! — at the top of the results panel. For n ≤ 18 the displayed value is exact down to the last digit (18! = 6,402,373,705,728,000 is less than Number.MAX_SAFE_INTEGER = 2⁵³ − 1). For 19 ≤ n ≤ 170 the value is a finite IEEE 754 approximation and the renderer applies scientific notation automatically — 100! displays as 9.332621544394415 × 10¹⁵⁷ rather than spelling out all 158 digits.
- Read the digit-count output for a quick sense of magnitude. 10! has 7 digits, 20! has 19 digits, 50! has 65 digits, 100! has 158 digits, 170! has 307 digits. The digit count is computed from ln(n!) / ln(10), which is exact at the digit-count granularity for every n in the supported range, so it is reliable even where the displayed n! has lost integer precision in the double conversion.
- Read ln(n!) — the natural logarithm of n! — when you need to work with factorials in log space. Poisson likelihoods, binomial log-coefficients, multinomial log-probabilities, and Stirling-formula derivations all live in log space precisely because they involve factorials that would otherwise overflow. ln(170!) ≈ 706.57, which is a perfectly comfortable double-precision number even though 170! itself is right at the edge of representability.
- Combine the three outputs to sanity-check by hand. For n = 10: the calculator returns 10! = 3,628,800, digit count 7 (3,628,800 has seven digits — confirmed), and ln(10!) = ln(3,628,800) ≈ 15.1044, which can be checked by computing ln(2) + ln(3) + … + ln(10) ≈ 0.693 + 1.099 + 1.386 + 1.609 + 1.792 + 1.946 + 2.079 + 2.197 + 2.303 ≈ 15.104.
- For arguments larger than n = 170 use a computer-algebra system that supports arbitrary-precision integers (Python's math.factorial, SageMath, PARI/GP, Mathematica). Alternatively if you only need ln(n!) or the order of magnitude, Stirling's approximation ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) gives a relative error below 10⁻⁵ even at n = 1,000 and is the standard tool for asymptotic estimates.
The formula.
The factorial is defined recursively as 0! = 1 and n! = n × (n−1)! for n ≥ 1. Unrolling the recursion gives the product form n! = n × (n−1) × (n−2) × … × 2 × 1 that is computed by every introductory factorial implementation. The Quanta engine computes n! exactly using a JavaScript BigInt accumulator: start with result = 1n, multiply by 2, then 3, then 4, up to n. Each multiplication is exact integer arithmetic — no rounding, no overflow in intermediate steps — and the final BigInt is converted to a Number only at the output boundary. For n ≤ 18 the converted Number is exactly equal to the BigInt (because 18! = 6,402,373,705,728,000 < 2⁵³ − 1 = Number.MAX_SAFE_INTEGER, so all integers up to 18! are representable without loss). For 19 ≤ n ≤ 170 the conversion is a normal double-precision rounding to the nearest representable double, which differs from the exact integer by at most one unit in the last place but remains finite and well-defined. At n = 170 the result is approximately 7.257 × 10³⁰⁶, just inside Number.MAX_VALUE ≈ 1.798 × 10³⁰⁸; at n = 171 the result would be approximately 1.241 × 10³⁰⁹ and overflows to +Infinity, which is why the calculator caps the input domain at 170. Stirling's approximation. Computing exact n! for very large n is impractical (memory and time grow with n), and in many applications all that is needed is the leading-order growth or the natural logarithm. Stirling's approximation, derived independently by Abraham de Moivre and James Stirling in the 1720s, gives n! ≈ √(2πn) · (n/e)ⁿ — equivalently, ln(n!) ≈ n·ln(n) − n + ½·ln(2πn). The relative error of this leading-order formula is about 1/(12n), so it has 1% accuracy at n = 8 and one-part-in-a-million accuracy by n = 100. The asymptotic series form, given in Abramowitz & Stegun §6.1.41 and NIST DLMF §5.11.1, includes higher-order Bernoulli-number corrections: ln(n!) ≈ n·ln(n) − n + ½·ln(2πn) + 1/(12n) − 1/(360n³) + 1/(1260n⁵) − … . The Quanta engine uses the first two correction terms (1/(12n) and 1/(360n³)) when n > 100, giving relative error below 10⁻¹⁴ for every n in that range — well within double-precision rounding. For n ≤ 100 the engine sums ln(i) for i = 1..n directly, which is faster and avoids any Stirling-error contribution at small n. Gamma-function extension. The gamma function Γ(z) is the unique smooth (more precisely, log-convex, by the Bohr–Mollerup theorem) function satisfying Γ(1) = 1 and Γ(z+1) = z·Γ(z). It is defined for Re(z) > 0 by the Euler integral Γ(z) = ∫₀^∞ t^(z−1) e^(−t) dt and extended to the rest of the complex plane (except the non-positive integers, where it has simple poles) by analytic continuation through the recursion. At non-negative integers Γ(n + 1) = n!, so the gamma function smoothly interpolates the factorial. At half-integers Γ(1/2) = √π, Γ(3/2) = √π/2, Γ(5/2) = 3√π/4 — the closed form Γ(n + 1/2) = (2n)! √π / (4ⁿ · n!) lets you write down every half-integer factorial in elementary terms. Numerical evaluation of Γ at arbitrary real or complex arguments is conventionally done via the Lanczos approximation (1964) or the Spouge approximation (1994), both of which yield 15-digit accuracy with a small fixed-degree polynomial. The Quanta calculator does not implement either approximation in this Tier 1 release — the 'extendToReals' toggle is reserved for a future upgrade — so non-integer n is rejected with an InvalidInputError that documents the limitation in its message.
A worked example.
Take n = 5. The engine starts with an accumulator result = 1n (BigInt one) and walks i from 2 up to 5, multiplying at each step. Step i = 2: result = 1 × 2 = 2. Step i = 3: result = 2 × 3 = 6. Step i = 4: result = 6 × 4 = 24. Step i = 5: result = 24 × 5 = 120. The loop exits with result = 120n. Converting to a JavaScript Number gives 120 exactly (well below MAX_SAFE_INTEGER), and the calculator returns factorial = 120 as the primary output. From ln(n!) the engine computes ln(120) ≈ 4.7875 (verified by hand: ln(2) + ln(3) + ln(4) + ln(5) = 0.6931 + 1.0986 + 1.3863 + 1.6094 = 4.7874), then divides by ln(10) ≈ 2.3026 to get log₁₀(120) ≈ 2.0792, takes the floor and adds 1, giving digitCount = 3 (verified: 120 has three digits). The naturalLogFactorial output is 4.7875 directly. As a cross-check, 5! is the number of ways to arrange five distinguishable items in a row — five books on a shelf, the letters A, B, C, D, E in order. Listing them: ABCDE, ABCED, ABDCE, ABDEC, ABECD, ABEDC, ACBDE, ACBED, ACDBE, ACDEB, ACEBD, ACEDB, ADBCE, ADBEC, ADCBE, ADCEB, ADEBC, ADECB, AEBCD, AEBDC, AECBD, AECDB, AEDBC, AEDCB. That is 24 orderings starting with A. By symmetry there are 24 starting with each of B, C, D, E, for a total of 5 × 24 = 120 orderings. Confirmed. Two larger benchmarks the calculator handles. For n = 10: factorial = 3,628,800, digit count 7, ln(10!) ≈ 15.1044. For n = 20: factorial = 2,432,902,008,176,640,000 (just inside the signed 64-bit integer range of 2⁶³ − 1 = 9,223,372,036,854,775,807), digit count 19, ln(20!) ≈ 42.3356. At n = 170, the very edge of the supported domain, the calculator returns approximately 7.257 × 10³⁰⁶ with digit count 307 and ln(170!) ≈ 706.5731 — a result that takes the BigInt engine roughly half a millisecond to compute exactly via 168 multiplications, then is converted to a finite IEEE 754 double for display.
Frequently asked questions.
Why is 0 factorial equal to 1?
How big is 170! and why is that the calculator's upper bound?
What is Stirling's approximation?
Can I compute the factorial of a non-integer like (1/2)!?
How are factorials used in permutations and combinations?
What is the difference between n! and n!! (double factorial)?
Why does the calculator return scientific notation for large factorials?
How do factorials show up in Taylor series and exponentials?
What is Wilson's theorem and how does it relate to factorials?
How accurate is the digitCount output for very large n?
References& sources.
- [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 the Quanta engine.
- [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]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]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]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]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.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 313 calculators remain free
- No billing is enabled