Factorial Calculator
Calculate the factorial of any non-negative integer (n!).
Did this tool answer your question?
Thanks — this helps us improve the tool.
How to use this tool
- Enter n in the fields above.
- Results update instantly as you type — or click Calculate.
- Read your n! and the full breakdown beneath it.
Calculate the factorial of any non-negative integer. For example, 5! = 5 × 4 × 3 × 2 × 1 = 120.
Formula
n! = 1 × 2 × 3 × … × n
For n = 0 or n = 1: 0! = 1, 1! = 1 (by definition). For any positive integer n: n! = ∏ni=2 i
How it works
The calculator takes the absolute value and rounds the input to the nearest integer, then multiplies all integers from 2 up through n together iteratively to produce n!. This method is exact for small integers but note that JavaScript's floating-point numbers lose precision for very large factorials (roughly n > 18).
Worked example
Worked example: 5!
- Start with n = 5.
- Multiply: 1 × 2 = 2.
- Continue: 2 × 3 = 6.
- Continue: 6 × 4 = 24.
- Continue: 24 × 5 = 120.
5! = 120
Common mistakes to avoid
- Entering a negative integer -- factorial is defined only for non-negative integers; a negative input should return an error rather than a numeric result.
- Confusing n! with n^n -- factorial multiplies descending integers (5! = 120), while n^n raises n to itself (5^5 = 3125); the latter grows far faster.
- Underestimating how rapidly factorial values grow: 20! exceeds 2.4 quintillion, and standard floating-point arithmetic loses exact integer precision above roughly n = 18-20.
Key terms
- Factorial (n!)
- The product of all positive integers from 1 up to n. By convention, 0! = 1.
- Integer
- A whole number with no fractional part (e.g., 0, 1, 2, 3…).
- Combinatorics
- The branch of mathematics that counts arrangements and selections; factorials appear throughout it.
- Overflow
- When a computed value exceeds the maximum number a data type can represent; large factorials exceed JavaScript's safe integer range.
Frequently asked questions
- What is a factorial?
- The factorial of n (written n!) is the product of all positive integers up to n. By definition, 0! = 1.