Factorial Calculator
Calculate n! for any non-negative integer. n! = n×(n-1)×⋯×1. Essential for combinations, permutations, and probability. Supports simplification of n!/k!
Formula & Reference
| Variable | Symbol | Formula | Units |
|---|---|---|---|
| Factorial Calculator | — | n! = n × (n-1) × ⋯ × 2 × 1 | integer |
Understanding Factorials
For a non-negative integer n, the factorial n! is the product of every positive integer from n down to 1. Thus 6! = 6×5×4×3×2×1 = 720. The special value 0! = 1 is not arbitrary: it keeps counting formulas consistent, because there is exactly one way to arrange or choose nothing.
Factorials appear whenever order matters. If n distinct objects can be arranged in a line, there are n! possible arrangements. Partial arrangements use P(n,r)=n!/(n-r)!, while combinations use C(n,r)=n!/[r!(n-r)!]. Writing these ratios symbolically before multiplying often cancels large factors and makes the arithmetic much easier.
Growth is extremely fast. Each step from n! to (n+1)! multiplies the previous value by n+1, so factorials soon exceed ordinary numeric ranges. This calculator evaluates exact floating-point factorials only through 170!, after which standard JavaScript numbers overflow. For larger n, logarithms, arbitrary-precision integers, or approximations such as Stirling's formula are more appropriate.
Step-by-Step Examples
5!
- 5×4×3×2×1=120
10!
- = 3,628,800
0!=1
- By definition; ensures C(n,0)=1
Cancel the shared 5! factor before multiplying.
- 8!/5! = 8×7×6
- 8×7×6 = 336
Seven distinct objects can be ordered in 7! ways.
- 7! = 7×6×5×4×3×2×1
- 7! = 5,040
Real-World Applications
Common Mistakes to Avoid
0!=1 by definition, required for boundary cases in formulas.
170! is maximum for float64. Use Stirling for larger n.
n!/k! = product from k+1 to n. Avoids huge intermediates.
The elementary factorial n! is defined here for non-negative integers. The gamma function extends the idea to many non-integer values, but that is a different computational model.
How to Interpret and Check Factorial Results
A simple recurrence gives the fastest check: n! must equal n×(n-1)!. If you know 9! = 362,880, then 10! must be 10×362,880 = 3,628,800. A result that does not satisfy this relationship is incorrect.
For factorial ratios, cancel first. For example, 12!/10! is only 12×11 = 132; computing both enormous factorials separately adds unnecessary work and increases the chance of overflow. In probability and combinatorics, also decide whether order matters before choosing between permutations and combinations.
Because factorials are counts, ordinary factorial answers are whole non-negative integers. Decimal inputs should not be silently treated as nearby integers. When estimating very large factorials, compare orders of magnitude using logarithms or Stirling's approximation rather than expecting a conventional decimal expansion.
Another useful check comes from divisibility. For n≥2, n! must be divisible by every positive integer from 1 through n. For example, 8!=40,320 is divisible by 7, 6, 5, and the smaller positive integers. Factorials also make ratios grow predictably: (n+1)!/n! = n+1. These simple identities are often faster to verify than recomputing a long product from the beginning.
This recurrence is also a convenient unit test when implementing factorial code.
Frequently Asked Questions
Related Math Calculators
Formula Explorer connections
Interpretation: This formula uses integer divisibility, modular arithmetic, finite fields or coding relationships. Assumption: Inputs are usually integers with specific modulus or coprimality requirements. Cryptographic examples are educational and not a substitute for vetted security libraries.