Big Number Calculator: Exact Arithmetic on Huge Integers
Enter whole numbers of any size, up to 10,000 digits, and choose an operation. Every digit of the answer is exact: no rounding, no scientific notation.
Last reviewed
Result
31 digits
about 1.267650600228e+30
- Digits
- 31
- Sum of the digits
- 115
- Trailing zeros
- 0
- Scientific form
- 1.267650600228e+30
Every digit is exact. Division rounds towards zero, and the remainder has the sign of the number being divided.
Why a calculator can get big numbers wrong
An ordinary calculator, or a spreadsheet, stores a number as a floating-point value. That form is fast and can hold very large or very small numbers, but it keeps only about 15 to 17 significant digits. Past that, the rest is rounded away and replaced with zeros or noise.
You can see it in a spreadsheet. Type 123456789012345678 and it may come back as 123456789012345000. And 2^100 shows as 1.26765E+30, with nearly thirty digits gone.
This calculator works on exact integers. Browsers can store a whole number of any size, and add, multiply and divide it with no rounding, using what JavaScript calls a BigInt. So the answer to 2^100 is the whole thing:
1,267,650,600,228,229,401,496,703,205,376
What it can do
| Operation | Example |
|---|---|
| Power, a^b | 2^100 = 1,267,650,600,228,229,401,496,703,205,376 |
| Factorial, a! | 25! = 15,511,210,043,330,985,984,000,000 |
| Multiply | (10³⁰ + 1)² = 1 000 000 000 000 000 000 000 000 000 002 000 000 000 000 000 000 000 000 000 001 |
| Add and subtract | 18,446,744,073,709,551,615 + 1 = 18,446,744,073,709,551,616 |
| Divide, with remainder | 10³⁰ ÷ 7 = 142,857,142,857,142,857,142,857,142,857 remainder 1 |
| Greatest common divisor | gcd(48, 180) = 12 |
| Modular power | 4^13 mod 497 = 445 |
The number 18,446,744,073,709,551,615 is the largest value a 64-bit unsigned integer can hold, which is one reason it appears in examples. Adding 1 to it is where fixed-size integers overflow, and where this calculator carries on.
How big do things get?
Some numbers to give a sense of scale:
- 2^1000 has 302 digits, and its digits add up to 1,366.
- 7^1000 has 846 digits.
- 100! has 158 digits, ends in 24 zeros, and its digits add up to 648.
- 20,000!, the largest factorial this will do, has 77,338 digits.
The result panel shows the number of digits, the sum of the digits, the trailing zeros and an approximate scientific form, to help you check an answer without reading it all.
Reading a very long result
The full result is in a box you can scroll and copy. A button copies the whole thing to the clipboard, ready to paste into a document, a program or a proof. For results over 24 digits the headline shows how many digits there are, instead of a number too wide to read.
Division, remainders and modulo
Integer division gives a whole-number quotient and a remainder. This calculator rounds the quotient towards zero, as most programming languages do, so the remainder takes the sign of the number being divided:
- 17 ÷ 5 = 3 remainder 2
- −17 ÷ 5 = −3 remainder −2
The relationship always holds: dividend = quotient × divisor + remainder.
Mathematicians usually want a remainder that is never negative. That is the modulo, shown as well: −17 mod 5 is 3.
Modular powers
The modular power a^b mod m gives the remainder of a^b after dividing by m, without ever working out the full power. It does this by squaring repeatedly and keeping only the remainder at each step, so a power with a billion digits can be reduced in a handful of steps.
The textbook example is 4^13 mod 497 = 445. Another, which you can check by hand: 3^200 mod 13 is 9, because 3³ = 27, which leaves 1 when divided by 13, so 3^198 leaves 1 and 3^200 leaves 3² = 9.
The calculation is the basis of several public-key methods in cryptography, where the numbers have hundreds of digits.
Some things to try
- How many digits does 2^10000 have? 3,011.
- How many zeros does 1000! end with? 249. Each trailing zero comes from a factor of 10, and there are more factors of 2 than 5, so it is the number of times 5 divides in: 200 + 40 + 8 + 1.
- What is the last digit of 7^123456? Use a modular power, 7^123456 mod 10, which is 1.
- Fermat’s little theorem. For a prime p, a^(p−1) mod p is 1. Try 123456789^1000000006 mod 1000000007, which is 1.
Limits
- Whole numbers only. A decimal such as 0.1 cannot be written exactly in this way, so it is not accepted.
- Inputs up to 10,000 digits, results up to 100,000 digits.
- Factorials up to 20,000.
- A power with a negative exponent is a fraction, and is not handled.
- Everything runs in your browser, and nothing is sent anywhere.
Common mistakes
- Typing a decimal point. Use whole numbers.
- Expecting the spreadsheet answer. A spreadsheet rounds. This does not.
- Forgetting that a negative remainder is correct. It follows from rounding the quotient towards zero, and the modulo gives the non-negative one.
- Trying to raise a large number to a large power. The result is limited to 100,000 digits, and the calculator says so.
For the factors of a number, see the common factor calculator. For patterns such as Fibonacci numbers, the number sequence calculator. For summarising numbers, the statistics calculator.
How it is calculated
The numbers are read as arbitrary-size integers. Addition, subtraction, multiplication, division and powers use exact integer arithmetic. A factorial multiplies the numbers up to the given value one after another. The greatest common divisor uses the Euclidean algorithm. A modular power uses repeated squaring, keeping only the remainder at each step. The digit count, digit sum and trailing zeros are read from the exact digits of the result.
Frequently asked questions
Why do ordinary calculators give the wrong answer for big numbers?
Most use floating-point numbers, which keep only about 15 to 17 significant digits. Beyond that, the digits are rounded away. This calculator uses exact integers, so every digit is right: 2^100 is 1,267,650,600,228,229,401,496,703,205,376.
How big can the numbers be?
Inputs can have up to 10,000 digits and a result up to 100,000 digits. A factorial can go up to 20,000, which is a number with 77,338 digits.
What is 100 factorial?
100! has 158 digits and ends in 24 zeros. The digits add up to 648. The calculator shows all of it, and you can copy it.
How does division work?
It is integer division: the quotient is rounded towards zero, and the remainder has the sign of the dividend, so that dividend = quotient × divisor + remainder. The modulo is also shown, which is never negative: −7 ÷ 2 is −3 remainder −1, and −7 mod 2 is 1.
What is a modular power for?
It finds a to the power b, divided by m, keeping only the remainder, without ever writing out the huge power. 4^13 mod 497 is 445. It is the basic operation in several kinds of cryptography.
Why can't I use decimals?
This works on whole numbers, where the answer can be exact to any length. A decimal such as 1/3 has no exact finite form, so for decimals use a calculator that works to a set number of places.
Related calculators
- Common Factor CalculatorEnter two to six whole numbers.
- Number Sequence CalculatorChoose the type of sequence, give the first term and the rule, and say how many terms.
- Statistics CalculatorEnter your numbers, separated by commas, spaces or new lines.
- Percentage CalculatorPick the question you are actually asking.
- Distance CalculatorChoose what you are measuring between.
- Mass CalculatorChoose how you know it.