Zero factorial equals one by empty-product convention
n! multiplies every positive integer up to n, so 5! is 120. Ancient Jain texts and the Sefer Yetzirah already explored the idea, Plato picked 7!, or 5,040, as the head count for his model city, and combinatorics later made factorials the standard count of the ways to order things.
To find the factorial of a whole number n, multiply together every number from 1 up to n: 5! = 5 × 4 × 3 × 2 × 1 = 120. Each value is the previous one times n, which is why 5! is just 5 × 24. By convention 0! equals 1: it is an empty product, and there is exactly one way to arrange zero objects, namely doing nothing. That choice keeps counting identities valid at the edges, such as there being one way to pick all n items from n.
Factorials surfaced independently in several cultures. The Jain Anuyogadvāra-sūtra, dated anywhere from 300 BCE to 400 CE, counts the possible orderings of a set of items. The Hebrew mystical book Sefer Yetzirah, from the Talmudic period of 200 to 500 CE, lists factorials up to 7! while working out how many words the Hebrew alphabet can form. Plato chose 5,040, which is 7!, as the population of an ideal community partly because it has so many divisors, yet there is no direct evidence that Greek mathematicians studied factorials as such.
Western interest took off in the late fifteenth century: Luca Pacioli computed factorials up to 11! in 1494 while puzzling over seating at dining tables. In 1729 James Stirling wrote to Abraham de Moivre with the approximation now named after him, which shows factorials outgrow exponential growth, and Daniel Bernoulli and Leonhard Euler extended the factorial to a continuous function, the gamma function. Louis Arbogast coined the word in 1800, and Christian Kramp introduced the exclamation mark in 1808.
The most basic job of n! is counting the ways to order n distinct objects, but it also appears in the power series for the exponential function and in algebra, number theory, probability, and computer science. Legendre's formula gives the exponent of each prime in a factorial and so counts its trailing zeros, and close relatives include binomial coefficients, double factorials, and subfactorials. Programmers often use the factorial as a stock example for comparing coding styles.
Source: Factorial