Factorial Calculator

Calculate the factorial of any non-negative integer. Enter a number to find its factorial (n!), which is the product of all positive integers less than or equal to n.

Updated June 2026 · How this works

How It Works
The formula, explained simply

A factorial calculator computes the product of all positive integers from 1 up to a given number n, denoted as n!. The calculation follows a simple multiplication pattern: n! = n × (n-1) × (n-2) × ... × 2 × 1. For any non-negative integer, this represents the number of ways to arrange n distinct objects in a sequence.

The factorial function has special cases that are important to understand. By mathematical definition, 0! = 1 and 1! = 1. These base cases ensure that factorial formulas work correctly in advanced mathematics, particularly in combinatorics and probability theory. The factorial grows extremely rapidly - while 10! = 3,628,800, just 13! exceeds 6 billion.

Factorial calculations are fundamental in many areas of mathematics. In combinatorics, n! represents the number of permutations of n distinct objects. In probability theory, factorials appear in calculating odds and distributions. The factorial function also appears in calculus through Taylor series expansions and in number theory through various mathematical proofs and identities.

When To Use This
Right tool, right situation

Use factorial calculations when determining the number of ways to arrange objects in a specific order. This is common in probability problems, such as calculating the odds of specific card arrangements or determining how many ways students can be seated in a classroom.

Factorials are essential in combinatorics problems involving permutations and combinations. When order matters (like race finishing positions), use factorial-based permutation formulas. When order doesn't matter (like choosing team members), use combination formulas that involve factorials in both numerator and denominator.

In advanced mathematics, factorials appear in Taylor series expansions, statistical distributions, and number theory. They're also used in computer science for analyzing algorithm complexity and in physics for statistical mechanics calculations involving particle arrangements and energy states.

Common Mistakes
Why results sometimes look wrong

A common mistake is forgetting that 0! = 1, not 0. This special case often confuses students, but it's essential for mathematical consistency. Another frequent error is attempting to calculate factorials of negative numbers, which are undefined in standard mathematics.

Many people underestimate how quickly factorials grow. While 5! = 120 seems manageable, 20! already exceeds 2 quintillion. This rapid growth means that factorial calculations become computationally challenging for large numbers, and most programming languages have upper limits for accurate factorial computation.

When using factorials in probability problems, students sometimes confuse permutations with combinations. Remember that n! gives the total arrangements of n objects, while combinations require dividing by the factorial of objects being chosen. Always double-check whether order matters in your specific problem before applying factorial formulas.

The Math
Worked examples and deeper derivation

The mathematical definition of factorial is: n! = n × (n-1) × (n-2) × ... × 2 × 1 for any positive integer n, with the special cases 0! = 1 and 1! = 1. This can also be expressed recursively as n! = n × (n-1)! where n > 0.

Factorials grow at an extraordinary rate, much faster than exponential functions. This rapid growth makes factorial calculations useful in estimating very large numbers of arrangements or combinations. The factorial function is closely related to the gamma function, where n! = Γ(n+1) for non-negative integers, extending the concept to non-integer values.

In combinatorics, factorials are essential for calculating permutations and combinations. The number of ways to choose r objects from n objects is given by the combination formula C(n,r) = n! / (r!(n-r)!). Similarly, the number of arrangements of r objects chosen from n objects is P(n,r) = n! / (n-r)!.

Basic Factorial
n = 4
4! = 4 × 3 × 2 × 1 = 24, representing all possible arrangements of 4 distinct items.
Probability Application
n = 6
6! = 720, the number of ways to arrange 6 people in a line or 6 books on a shelf.
Large Factorial
n = 12
12! = 479,001,600, useful in calculating permutations of 12 distinct objects.

Common questions

What is factorial and how do you calculate it?
A factorial (n!) is the product of all positive integers from 1 to n. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120. By definition, 0! = 1. Factorials are fundamental in combinatorics, probability theory, and permutation calculations.
Why is 0 factorial equal to 1?
0! = 1 by mathematical convention and logical necessity. This definition makes factorial formulas work correctly in combinatorics. There's exactly one way to arrange zero objects (do nothing), so 0! = 1. This also ensures that the factorial function follows the recursive relationship n! = n × (n-1)!
What is the largest factorial JavaScript can calculate?
JavaScript can accurately calculate factorials up to 170! before reaching infinity due to floating-point precision limits. 170! is approximately 7.26 × 10^306, which is near the maximum value JavaScript can represent. Numbers above 170 factorial exceed these limits.

Need something this doesn't cover?

Suggest a tool — we'll build it →