Factorial calculator

Every digit of n!, however many there are. Ordinary floating point gets 23! wrong and gives up entirely at 171!, so this uses arbitrary-precision integers and shows you what the double would have said. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.

23! is the first one a computer gets wrong

A factorial grows faster than almost anything else in ordinary arithmetic, and it runs into two separate walls:

22!the last one a double holds exactly
23!finite, plausible, and wrong
170!the last one that is finite at all
171!Infinity

The first wall is 253, past which a double has no room for every whole number, so the running product picks up a rounding at every step and never loses it. The second is about 1.8×10308, the largest number a double can represent at all.

The gap between them is the dangerous part. From 23! to 170! a calculator returns an answer that is finite, has a sensible number of digits, and is not correct. Infinity at least announces itself.

What this page does instead

Arbitrary-precision integers — BigInt — have no size limit beyond memory and patience, and every digit is exact. 171! has 310 of them and they are all above. The page caps the input only because printing a few thousand digits is not useful to anybody, and it says where the cap is rather than silently truncating.

The same applies to n choose r, which is where factorials usually get used. 200 choose 100 is an ordinary 61-digit number; its three factorials are each hundreds of digits. Computing it by cancelling as you go keeps every intermediate small, which is why this page shows it without ever forming 200!.

Why 5! tells you nothing

5! is 120 whether you use floating point, integers, or a pencil. So is 10!, and so is 20!. Every worked example of a factorial in every textbook is inside the range where a double is perfectly exact, which is why a calculator can be tested, shipped and used for years before anybody puts 23 into it.

A factorial is only defined for whole numbers from zero upwards. There is no way to multiply together all the whole numbers up to 4.5, and this page says so rather than quietly using the gamma function, which answers a related but different question.

Where to go next