Factorial Calculator
Enter a non-negative integer n to compute n! (factorial).
Back to all tools on ToolForge
n
Result
About Factorial Calculator
This factorial calculator computes `n!` for a non-negative integer.
It is useful for permutations, combinations, probability problems and classroom math where factorial values come up often.
Factorial Formula and Examples
// Factorial definition:
// n! = n × (n-1) × (n-2) × ... × 2 × 1
// 0! = 1 (by convention)
// Examples:
// 0! = 1
// 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
// JavaScript implementation (iterative):
function factorial(n) {
let result = 1;
for (let i = 2; i <= n; i++) {
result *= i;
}
return result;
}
Factorial Values Reference Table
| n | n! | Scientific Notation |
|---|---|---|
| 0 | 1 | 1×10^0 |
| 1 | 1 | 1×10^0 |
| 2 | 2 | 2×10^0 |
| 3 | 6 | 6×10^0 |
| 4 | 24 | 2.4×10^1 |
| 5 | 120 | 1.2×10^2 |
| 6 | 720 | 7.2×10^2 |
| 7 | 5,040 | 5.04×10^3 |
| 8 | 40,320 | 4.03×10^4 |
| 9 | 362,880 | 3.63×10^5 |
| 10 | 3,628,800 | 3.63×10^6 |
| 15 | 1,307,674,368,000 | 1.31×10^12 |
| 20 | 2,432,902,008,176,640,000 | 2.43×10^18 |
Permutations and Combinations
// Permutations (order matters): // P(n,r) = n! / (n-r)! // Example: Arrange 3 books from 5: P(5,3) = 5!/2! = 60 // Combinations (order doesn't matter): // C(n,r) = n! / (r! × (n-r)!) // Example: Choose 3 books from 5: C(5,3) = 5!/(3!×2!) = 10 // Binomial coefficient (n choose r): // C(n,r) = n! / (r! × (n-r)!) // Used in binomial theorem: (a+b)^n = Σ C(n,k) × a^(n-k) × b^k
Stirling's Approximation
For large n, factorial can be approximated:
n! ≈ √(2πn) × (n/e)^n // More accurate version: n! ≈ √(2πn) × (n/e)^n × (1 + 1/(12n)) // Example: 10! // Exact: 3,628,800 // Stirling: √(20π) × (10/e)^10 ≈ 3,598,696 // Error: ~0.8%
Frequently Asked Questions
- What is a factorial and how is it calculated?
- The factorial of n (denoted n!) is the product of all positive integers from 1 to n. Formula: n! = n × (n-1) × ... × 2 × 1. By convention, 0! = 1. Example: 5! = 5×4×3×2×1 = 120. Factorials grow extremely fast: 10! = 3,628,800, 20! ≈ 2.4 quintillion.
- What are factorials used for in mathematics?
- Factorials are fundamental in: combinatorics (counting permutations and combinations), probability theory (calculating odds), calculus (Taylor series coefficients), statistics (binomial distributions), and algebra (binomial theorem). They count the number of ways to arrange n distinct objects.
- What is the recursive formula for factorials?
- The recursive definition is: n! = n × (n-1)! with base case 0! = 1. This means 5! = 5 × 4! = 5 × 24 = 120. Recursive formulas are elegant but iterative calculation is more efficient for large numbers to avoid stack overflow in programming.
- How fast do factorials grow?
- Factorials grow faster than exponential functions. Stirling's approximation: n! ≈ √(2πn) × (n/e)^n. For large n: 10! = 3.6M, 15! = 1.3T, 20! = 2.4 quintillion, 52! ≈ 8×10^67 (more than atoms in the observable universe). JavaScript can accurately compute up to 170! before overflow.
- What is the double factorial notation?
- Double factorial (n!!) multiplies every other integer: n!! = n × (n-2) × (n-4) × ... For odd n: 7!! = 7×5×3×1 = 105. For even n: 8!! = 8×6×4×2 = 384. By convention: 0!! = 1 and (-1)!! = 1. Used in combinatorics and special function theory.
- How do you calculate permutations and combinations using factorials?
- Permutations (order matters): P(n,r) = n!/(n-r)!. Combinations (order doesn't matter): C(n,r) = n!/(r!×(n-r)!). Example: From 52 cards, there are C(52,5) = 2,598,960 possible 5-card hands, but P(52,5) = 311,875,200 ordered sequences.