n! nPr nCr
Last reviewed: January 2026
Calculate factorials (n!), permutations (nPr), and combinations (nCr) for any positive integers. This calculator runs entirely in your browser — your data stays private, and no account is required.
A factorial (n!) is the product of all positive integers from 1 to n: 5! = 5 × 4 × 3 × 2 × 1 = 120. Factorials grow astronomically fast — 20! already exceeds 2 quintillion, and 52! (the number of ways to shuffle a deck of cards) has 68 digits.[1] Factorials are foundational to combinatorics: the number of permutations of n items is n!, and combinations use factorials in the formula C(n,r) = n!/(r!(n-r)!).[2] By convention, 0! = 1, which is not arbitrary but necessary for combinatorial formulas to work correctly — there is exactly one way to arrange zero objects.[3] Use the Combination Calculator for counting problems that use factorials.
Lottery odds: choosing 6 numbers from 49 = C(49,6) = 13,983,816 combinations. Every combination is equally likely, so the odds of winning are 1 in ~14 million. Password security: an 8-character password using 94 printable ASCII characters has 94⁸ ≈ 6.1 × 10¹⁵ possibilities — very different from factorial calculation (ordering a set) because characters can repeat. Tournament brackets: C(64,2) = 2,016 possible first-round matchups in a 64-team bracket. The "birthday problem": the odds that 2 of 23 random people share a birthday are over 50% — proven using combinations and probability.
| n | n! | Digits | Use Case |
|---|---|---|---|
| 5 | 120 | 3 | Small permutations |
| 10 | 3,628,800 | 7 | Combination problems |
| 15 | 1,307,674,368,000 | 13 | Card game odds |
| 20 | 2.43 × 10¹⁸ | 19 | Cryptography |
| 52 | 8.07 × 10⁶⁷ | 68 | Deck shuffling |
The distinction between permutations and combinations trips up students and professionals alike, yet it governs everything from password security to genetic analysis. A permutation counts arrangements where order matters: how many ways can you seat 5 people in 5 chairs? The answer is 5! = 120, because each position is distinct. A combination counts selections where order is irrelevant: how many 5-card poker hands can be dealt from 52 cards? That is C(52,5) = 2,598,960. The key question is always whether rearranging the same items produces a different outcome. If you are forming a committee, order does not matter — use combinations. If you are assigning ranked prizes, order matters — use permutations.
The permutation formula nPr = n!/(n−r)! gives the number of ordered arrangements of r items chosen from n. The combination formula nCr = n!/(r!(n−r)!) removes duplicate orderings by dividing by r!. For any given n and r, nPr is always greater than or equal to nCr because permutations distinguish between arrangements that combinations treat as identical. When r = n, nPn = n! (every item is placed) and nCn = 1 (there is only one way to choose all items regardless of order).
Factorials underpin the binomial coefficient, which appears throughout statistics. The probability of getting exactly k successes in n independent trials with success probability p is C(n,k) × p^k × (1−p)^(n−k). This binomial distribution uses factorials three times within a single probability calculation. In hypothesis testing, permutation tests shuffle observed data to create a null distribution — the number of possible shuffles is n!, making exact computation feasible only for small samples. For larger datasets, statisticians use sampling or Stirling's approximation to estimate factorial-based quantities.
The multinomial coefficient extends combinations to multiple groups: n!/(k₁!k₂!...kₘ!) counts the ways to divide n items into m groups of specified sizes. Distributing 12 jurors into 3 deliberation rooms of 4 each uses the multinomial coefficient: 12!/(4!4!4!) = 34,650 possible assignments. This appears in natural language processing for word-frequency models and in genetics for allele distribution calculations.
Standard 64-bit floating-point numbers overflow at 170! (which has 307 digits), so computing exact factorials beyond this point requires arbitrary-precision arithmetic libraries. Programming languages like Python handle big integers natively, but JavaScript loses precision beyond 2⁵³. This calculator uses big-number techniques to display exact results for inputs well beyond what standard arithmetic supports. When exact values are unnecessary, Stirling's approximation (n! ≈ √(2πn)(n/e)ⁿ) provides logarithmic estimates that are accurate to within 1% for n > 10 and improve rapidly as n grows.
The gamma function Γ(n) = (n−1)! extends factorials to non-integer and even complex numbers. Γ(0.5) = √π ≈ 1.7725, meaning "half factorial" has a precise mathematical value. This extension is essential in advanced statistics (the chi-squared distribution uses gamma functions), physics (partition functions in thermodynamics), and engineering (signal processing). While this calculator handles integer factorials, understanding the gamma function connection reveals why factorials appear in so many scientific formulas — they are a special case of a much broader mathematical structure.
Algorithm complexity analysis frequently involves factorials. The traveling salesman problem — finding the shortest route visiting n cities exactly once — has n!/2 possible routes when the starting city is fixed. For 20 cities, this is over 60 quadrillion routes, making brute-force solutions computationally impossible. This is why the problem is classified as NP-hard: no known algorithm solves it efficiently for large n. Heuristic methods like nearest-neighbor, simulated annealing, and genetic algorithms find good (but not guaranteed optimal) solutions in reasonable time. Understanding that n! grows faster than any exponential function (2ⁿ, 3ⁿ, etc.) explains why factorial-complexity problems are considered intractable.
Hash functions and cryptographic protocols rely on factorial-sized spaces for security. The number of possible orderings of a 256-element set is 256!, a number with 507 digits — far larger than the number of atoms in the observable universe (approximately 10⁸⁰). This immense size makes certain brute-force attacks mathematically impossible within the lifetime of the universe. Factorial-based counting also appears in database query optimization (determining the most efficient join order for n tables requires evaluating n! orderings), compiler design (register allocation), and network routing (packet switching through n nodes).
A derangement is a permutation where no element appears in its original position. The number of derangements of n items, denoted !n or D(n), equals n! × Σ(−1)^k/k! for k from 0 to n. For large n, the probability of a random permutation being a derangement approaches 1/e ≈ 36.79%. The classic illustration is the "hat check" problem: if n people check their hats and the hats are returned randomly, the probability that nobody receives their own hat is approximately 1/e regardless of how many people are involved. This counterintuitive result — that the probability stabilizes almost immediately and does not approach 0 or 1 — is a fundamental result in combinatorics with applications in cryptography, genetics (random chromosome segregation), and card shuffling analysis.
See also: Prime Number Checker · Exponent Calculator · GCD & LCM Calculator
→ Factorials grow faster than exponential functions. 10! = 3,628,800. 20! = 2.4 × 10¹⁸. 100! has 158 digits. A deck of 52 cards can be arranged in 52! ≈ 8 × 10⁶⁷ ways — more than the number of atoms in the observable universe.
→ 0! = 1 by definition, not by intuition. This isn't a mistake — it's necessary for the combination formula to work. C(n,0) should equal 1 (there's one way to choose nothing), and the formula C(n,0) = n!/(0!×n!) requires 0! = 1 to produce the correct answer.
→ Use Stirling's approximation for very large factorials. n! ≈ √(2πn) × (n/e)ⁿ. This approximation is surprisingly accurate for n > 10 and is used in statistics, physics, and computer science when exact factorials would overflow calculators.
→ Factorials appear everywhere in probability. The number of ways to arrange n distinct items is n!. The number of ways to choose r items from n is n!/(r!(n-r)!). See our Combination Calculator, Permutation Calculator, and Probability Calculator for applied counting problems.
See also: Combination Calculator · Permutation Calculator · Probability Calculator · Scientific Calculator