The factorial of a non-negative integer n, written as n!, is the product of all positive integers from 1 to n. For example, 5! = 5 x 4 x 3 x 2 x 1 = 120. Factorials appear everywhere in combinatorics, probability, algebra, and calculus. They count the number of ways to arrange n distinct objects, form the denominators in Taylor series expansions, and show up in the Poisson distribution, binomial coefficients, and the gamma function. The notation n! was introduced by Christian Kramp in 1808, though the concept dates back to the 12th-century Indian mathematician Bhaskara II. This calculator computes standard factorials, double factorials, and subfactorials (derangements) with step-by-step breakdowns.
What This Calculator Does
Enter a non-negative integer and choose a factorial type. The calculator computes the result, counts the number of digits, counts trailing zeros (for standard factorials), and shows the step-by-step multiplication for small inputs. It supports three types: standard factorial (n!), double factorial (n!!), and subfactorial (!n, also called the derangement number).
Factorials are used extensively in combinatorics. Use our Permutation and Combination Calculator to compute permutations and combinations that rely on factorials. You can also explore Probability Calculator for event probability calculations, or our Exponent Calculator for power calculations.
Supported Factorial Types
- Standard Factorial (n!): n x (n-1) x ... x 2 x 1. By convention, 0! = 1. Maximum supported: n = 170
- Double Factorial (n!!): n x (n-2) x (n-4) x ... down to 1 (for odd n) or 2 (for even n). For example, 7!! = 7 x 5 x 3 x 1 = 105
- Subfactorial (!n): The number of derangements of n objects (permutations where no element appears in its original position). Computed as floor(n!/e). For example, !4 = 9
Outputs Provided
- Factorial value: The exact result (or scientific notation for large values)
- Number of digits: How many digits the result contains
- Trailing zeros: Count of consecutive zeros at the end (standard factorial only)
- Step-by-step: The multiplication breakdown for small inputs (n up to 20)
How the Calculation Works
Standard: n! = n x (n-1) x (n-2) x ... x 2 x 1
Double: n!! = n x (n-2) x (n-4) x ... (stop at 1 or 2)
Subfactorial: !n = floor(n! / e) = n! x sum of (-1)^k / k! for k=0 to n
Trailing zeros: floor(n/5) + floor(n/25) + floor(n/125) + ...
Stirling's approximation: n! approx sqrt(2*pi*n) x (n/e)^n
The standard factorial is computed by a simple loop multiplying integers from 1 to n. For n greater than 170, the result exceeds JavaScript's maximum numeric value (approximately 1.8 x 10 to the 308th), and the calculator reports an overflow. The double factorial multiplies every other integer, stepping by 2. The subfactorial is computed using the formula floor(n!/e), which gives the exact integer result. Trailing zeros are counted using Legendre's formula: each trailing zero comes from a factor of 10, which is 2 x 5. Since there are always more factors of 2 than 5 in a factorial, the number of trailing zeros equals the number of factors of 5, computed as the sum of floor(n/5^k) for k = 1, 2, 3, ... until 5^k exceeds n.
How to Use the Calculator
- Select the factorial type (standard, double, or subfactorial)
- Enter a non-negative integer (0 to 170 for standard, 0 to 300 for double)
- Read the result, number of digits, and trailing zeros
- For small inputs (n up to 20), review the step-by-step multiplication
Example Calculations
A student in Chicago needs to compute 8! to find the number of ways to arrange 8 books on a shelf.
- 8! = 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1
- 8! = 40,320
- Number of digits: 5
- Trailing zeros: 1 (from the factor 5 x 2 = 10)
In a second example, a probability student in Seattle needs to find the number of derangements of 6 items (permutations where no item is in its original position).
- !6 = floor(6! / e) = floor(720 / 2.71828...) = floor(264.87) = 265
- Subfactorial of 6: 265
- This means there are 265 ways to permute 6 items so that none is in its original position
Real-World Scenarios
Password Security Analysis in San Francisco
A cybersecurity analyst at a fintech company in San Francisco is evaluating the strength of a password policy. The policy requires 12-character passwords using only lowercase letters (26 options per character). The total number of possible passwords is 26 to the 12th power, but the analyst also needs to compute the number of possible arrangements if all 26 letters were used exactly once (a permutation of the alphabet). Using the factorial calculator with n = 26, the result is 26! which is approximately 4.03 x 10 to the 26th. This is about 403 septillion possible arrangements. The analyst compares this to the 95 to the 12th power possible 12-character passwords using all printable ASCII characters, which is approximately 5.4 x 10 to the 23rd. Surprisingly, the permutation of 26 letters is harder to brute-force than a 12-character random ASCII password. The National Institute of Standards and Technology (NIST) Special Publication 800-63B provides guidance on password strength estimation, and factorials directly inform the entropy calculations.
Combinatorial Chemistry in Cambridge, Massachusetts
A research chemist at MIT in Cambridge, Massachusetts is designing a combinatorial library of peptide compounds. She wants to know how many different peptides can be formed by arranging 8 different amino acids in a chain. Using the factorial calculator with n = 8, she gets 8! = 40,320 possible arrangements. If she extends to 10 amino acids, 10! = 3,628,800. At 15 amino acids, 15! = 1.31 x 10 to the 12th, which exceeds a trillion compounds. This exponential growth explains why combinatorial chemistry is powerful but also why screening all possible combinations becomes impractical. The chemist uses this information to design a focused library of 8-amino-acid peptides that can be screened in a 384-well plate format, requiring about 105 plates to cover all 40,320 combinations. The American Chemical Society publishes guidelines for combinatorial library design that reference these combinatorial principles.
Queueing Theory for Airport Security in Atlanta
An operations research analyst at Hartsfield-Jackson Atlanta International Airport is modeling queue behavior at TSA checkpoints. She needs to compute the number of ways to reorder a queue of 10 passengers such that no passenger ends up in their original position (a derangement). Using the subfactorial mode with n = 10, she gets !10 = 1,334,961. Out of 10! = 3,628,800 total permutations, 1,334,961 are derangements, meaning about 36.8% of all permutations have no fixed point. This ratio approaches 1/e (approximately 0.3679) as n grows, which is a well-known result in combinatorial probability. The analyst uses this to model the probability that a queue reshuffling results in no passenger being in the same position, which informs the design of random queue reassignment protocols. The Transportation Security Administration uses queueing theory models for staffing optimization at major airports.
Common Mistakes to Avoid
- Computing 0! as 0: By definition, 0! = 1. This convention is necessary because there is exactly one way to arrange zero objects (the empty arrangement), and it makes combinatorial formulas work correctly. The recursive definition n! = n x (n-1)! requires 0! = 1 as the base case
- Confusing factorial with exponentiation: 5! is not 5 to the 5th. 5! = 120, while 5 to the 5th = 3,125. Factorials grow faster than exponentials for large n. The crossover happens around n = 3 for small bases, but factorials eventually overtake any fixed-base exponential
- Applying factorials to non-integers: The factorial function is defined only for non-negative integers. For non-integer values, use the gamma function: Gamma(n+1) = n! for integer n, and Gamma is defined for all real and complex numbers except non-positive integers. This calculator does not compute the gamma function
- Forgetting that factorials grow extremely fast: 10! is already over 3 million. 20! exceeds 10 to the 18th. 70! exceeds 10 to the 100th (a googol). This rapid growth means factorials quickly exceed practical computation limits, which is why this calculator caps at n = 170 for standard factorials
Limitations of This Calculator
This calculator uses JavaScript's native number type (IEEE 754 double-precision floating point), which limits standard factorials to n = 170. For n greater than 170, the result exceeds Number.MAX_VALUE and the calculator reports an overflow. For exact computation of larger factorials, use a big-integer library or a computer algebra system like Mathematica, Maple, or Python's math.factorial with arbitrary precision. The step-by-step breakdown is only shown for n up to 20 to keep the output readable. The subfactorial uses the floor(n!/e) formula, which is exact for all supported n but relies on the precision of the mathematical constant e. The double factorial supports n up to approximately 300. This calculator does not compute the gamma function, log-factorials, or Stirling's approximation, though the formula for Stirling's approximation is shown for reference.
Authoritative Research and Resources
- Wolfram MathWorld: Factorial - A comprehensive mathematical reference from Wolfram Research covering the factorial function, its properties, generalizations (gamma function, double factorial, multifactorial), and connections to other areas of mathematics.
- NIST Digital Library of Mathematical Functions: Gamma Function - The National Institute of Standards and Technology's authoritative reference for the gamma function, which generalizes the factorial to non-integer arguments. Chapter 5 covers properties, computation methods, and asymptotic expansions.
- Khan Academy: Factorials and Seat Arrangements - A free educational resource with video lessons explaining how factorials count arrangements, with worked examples and practice exercises aligned with Common Core standards.