Factorial

Calculate n! for non-negative integers.

{{ factorialCalc.message }}

Overview

The concept of factorial first appears in Indian mathematical sources of the sixth century AD, in the works of astronomer Varāhamihira, who used permutations of ingredients in practical contexts. In the West, British mathematician Fabian Stedman documented, in 1677, the relationship between factorial and permutations in the context of change ringing — the ordered swapping of bells in English church towers, a collective musical art where the goal was to sound every possible sequence of n bells exactly once. The symbol n! was introduced by French mathematician Christian Kramp in 1808, a notational choice that became a universal standard. The formal definition includes 0! = 1 — a result that feels counterintuitive but is consistent: there is exactly one way to arrange zero objects, which is to do nothing. Leonhard Euler generalized factorial to non-integers with the Gamma function (Γ), defined in 1729: Γ(n) = (n-1)! for positive integers, but valid for any complex number except negative integers.

Factorial appears in virtually every area of combinatorial mathematics. Permutations: the number of ways to arrange n distinct objects is n!. Combinations: C(n,k) = n! / (k! × (n-k)!) — the formula behind Pascal's triangle and Newton's binomial theorem. Probability: a 52-card deck can be shuffled in 52! ≈ 8.07 × 10^67 distinct ways — a number so large it is statistically improbable that any two decks have ever been shuffled in the same order in all of human history. In algorithm analysis, factorial appears in O(n!) complexity, which describes brute-force algorithms for the Traveling Salesman Problem and other NP-hard problems.

The computational challenge of factorial is instructive: values grow so fast they exceed the capacity of the 64-bit IEEE 754 double-precision floating point type at 171! — which is why this tool limits calculation to n ≤ 170, where 170! ≈ 7.26 × 10^306 still fits in a double. Stirling's approximation (1730), developed by James Stirling, gives an excellent logarithmic estimate particularly useful in theoretical analysis when factorial appears inside more complex expressions. For larger values, languages like Python offer arbitrary-precision integers and compute 1000! exactly — a number with 2,568 digits — with no overflow whatsoever. If you just need the quick result of a specific n!, enter the value and get the result and its scientific notation instantly.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Example — 5! = 120

Code Snippets

Code example
5! = 120

Example

5! = 120

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.