terican

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.

FreeInstantNo signupOpen source

Inputs

Factorial (n!)

Explain my result

0/3 free

Get a plain-English breakdown of your result with practical next steps.

Factorial (n!)

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

Frequently asked questions

What is a factorial and how is it calculated?
The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 through n. To compute 5!, multiply 5 × 4 × 3 × 2 × 1 = 120. The special case 0! equals 1 by convention. Factorials grow extremely fast: 10! = 3,628,800 and 20! exceeds 2.4 quintillion, making them indispensable in combinatorics, probability, and calculus.
Why does 0! equal 1?
Zero factorial equals 1 because of the empty product rule: the product of no numbers is defined as 1, the multiplicative identity. This convention is also mathematically required for consistency. The binomial coefficient C(n, 0) = n! / (0! × n!) must equal 1 because exactly one way exists to choose zero items from any set. Without 0! = 1, combinatorial formulas break down completely and cannot be evaluated at boundary cases.
What is the maximum number this factorial calculator supports?
This factorial calculator accepts inputs from 0 to 170. The value 170! is approximately 7.26 × 10^306, just within the range of a 64-bit IEEE 754 double-precision floating-point number, whose maximum is roughly 1.8 × 10^308. At n = 171, the result exceeds this limit and overflows to Infinity. The calculator enforces a maximum of 170 to guarantee accurate, finite numeric output for every valid input.
What are the main real-world uses of factorials?
Factorials have broad applications across science and engineering. They count permutations: 6 distinct objects can be arranged in 6! = 720 ordered ways. They power the binomial coefficient used in probability, such as computing the 2,598,960 possible 5-card poker hands. In calculus, Taylor series for e^x, sin(x), and cos(x) use factorial denominators. In physics, factorials count microstates of thermodynamic systems, directly connecting n! to entropy and statistical mechanics.
How do factorials relate to permutations and combinations?
Permutations count ordered arrangements: the number of ways to arrange n distinct objects in a sequence equals n!. Combinations count unordered selections using the binomial coefficient C(n, k) = n! / (k! × (n−k)!). For example, choosing 3 committee members from 10 candidates gives C(10, 3) = 10! / (3! × 7!) = 120 possible committees, while arranging those same 3 members in a line gives 3! = 6 distinct ordered sequences.
Can factorials be calculated for non-integer or negative numbers?
The standard factorial n! is defined only for non-negative integers (0, 1, 2, 3, …). The concept extends to real and complex numbers through the Gamma function, where Γ(n) = (n−1)! for positive integers. For non-integer values, Γ(1.5) = √π/2 ≈ 0.886. However, the Gamma function is undefined for negative integers, which have poles. This calculator handles only non-negative integers from 0 to 170 under the standard definition.