Fibonacci
calculator.
Find any Fibonacci number exactly, list a run of terms, or test a number you have.
- Digits
- 11
- F(50) ÷ F(49)
- 1.618034
F(50) is 7,778,742,049 plus 4,807,526,976, the two terms before it. It has 11 digits, and each term is close to 1.618 times the one before.
Ratio of neighbors closing in on φ
The ratio of each term to the one before jumps between 2 and 1.5 at first, then settles on φ = 1.618034. By n = 20 it is 1.618033999.
Fibonacci squares
Squares with sides 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 fill a 89 by 55 rectangle. A quarter circle in each square traces the spiral.
Working
- 1Start from the two seedsF(0) = 0 and F(1) = 1
- 2Fast doubling jumps from F(k) to F(2k)F(2k) = F(k)(2F(k + 1) − F(k)) and F(2k + 1) = F(k)² + F(k + 1)² reach F(50) in about 6 halvings instead of 50 additions
- 3Binet's formula, rounded to a whole numberroundφ50√5= 12,586,269,025
- 4Check: the two terms before it add up to itF(49) + F(48) = 7,778,742,049 + 4,807,526,976 = 12,586,269,025
- 5Check: Cassini's identity gives 1 or −1F(49) × F(51) − F(50)2 = 1
Terms around F(50)
| n | F(n) | Ratio |
|---|---|---|
| 45 | 1,134,903,170ratio 1.61803399 | 1.61803399 |
| 46 | 1,836,311,903ratio 1.61803399 | 1.61803399 |
| 47 | 2,971,215,073ratio 1.61803399 | 1.61803399 |
| 48 | 4,807,526,976ratio 1.61803399 | 1.61803399 |
| 49 | 7,778,742,049ratio 1.61803399 | 1.61803399 |
| 50 | 12,586,269,025ratio 1.61803399 | 1.61803399 |
| 51 | 20,365,011,074ratio 1.61803399 | 1.61803399 |
| 52 | 32,951,280,099ratio 1.61803399 | 1.61803399 |
| 53 | 53,316,291,173ratio 1.61803399 | 1.61803399 |
| 54 | 86,267,571,272ratio 1.61803399 | 1.61803399 |
| 55 | 139,583,862,445ratio 1.61803399 | 1.61803399 |
Every digit of F(50)
12,586,269,025
11 digits, worked out with exact whole-number arithmetic. Copy takes them all.
How it's worked out
Each term is the sum of the two before it. The sequence starts from F(0) = 0 and F(1) = 1, so it runs 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and on without end.
Adding one term at a time takes n steps, which is slow for a large n. Fast doubling skips ahead instead. From F(k) and F(k + 1) it gets F(2k) and F(2k + 1) in one go, so each step halves the distance. F(100,000) has 20,899 digits and takes about 17 of these steps. Every digit is kept, because the tool works in whole numbers of any length rather than in decimals.
Binet's formula gives the same terms from powers of the golden ratio φ, which is about 1.618034. MathWorld writes it as a difference of two powers over √5. The second power shrinks toward 0, so rounding the first alone gives the term. For n = 30 that rounding gives 832,040, which is F(30).
Testing a number uses a fact recorded in the OEIS entry. A whole number x is a Fibonacci number exactly when 5x² + 4 or 5x² − 4 is a perfect square. The tool takes exact integer square roots, so the test still holds for a number thousands of digits long.
Worked examples
Priya checks her code for F(100)
Priya's program prints the 100th Fibonacci number, and she wants to know if it is right. F(100) = 354,224,848,179,261,915,075, a number with 21 digits. It is the sum of F(99) = 218,922,995,834,555,169,026 and F(98) = 135,301,852,344,706,746,049.
If her program uses unsigned 64-bit integers, it can only hold terms up to F(93). Past that point the value wraps around and prints nonsense. In double-precision floating point, the kind most languages use for decimals, the last exact term is F(78), so a program that prints F(100) from doubles gets the first digits right and the rest wrong.
Is 102,334,155 a Fibonacci number?
Leo found 102,334,155 in a puzzle book and suspects it is a Fibonacci number. Five times its square, plus 4, is 52,361,396,397,820,129. That is 228,826,127 squared, a perfect square, so the number is in the sequence.
Its place is F(40). Working out F(40) directly gives 102,334,155, the same number. With a long number a decimal square root rounds, which is why the test has to be done in whole numbers.
Writing 100 as Fibonacci numbers
A student is asked to write 100 as a sum of Fibonacci numbers, using no two terms that sit next to each other. 100 is not itself a term: it falls between 89 and 144.
Take the largest term that fits each time. That gives 100 = 89 + 8 + 3, and the parts add back to 100. Zeckendorf's theorem says every positive whole number has exactly one sum like this.
Reading your result
Check how your source counts. This tool, the OEIS and most textbooks use F(0) = 0. If a course calls 0 the first term, then its 100th term is F(99) = 218,922,995,834,555,169,026, one step back from F(100).
The ratio swings around φ. F(6) ÷ F(5) is 1.6, which is below φ, and F(11) ÷ F(10) is 1.618182, just above it. Each pair lands on the other side of φ and a little closer. So the ratios zigzag at first and then flatten out.
Negative indexes alternate in sign. Running the rule backward gives F(−n) = (−1)^(n + 1) F(n). So F(−8) = −21, while F(8) = 21.
Big answers are rounded on screen only. F(1,000) has 209 digits. The answer is shown rounded to 5 significant figures, 4.3467 × 10^208, and the full number is listed digit by digit.
Lucas numbers come along for free. They follow the same rule but start from 2 and 1, and each one is the sum of the Fibonacci terms either side: L(10) = F(9) + F(11) = 123. The check in the working uses another identity, Cassini's: F(9) × F(11) − F(10)² = 1. The answer is always 1 or −1.
Common mistakes
- Counting from 1 when the source counts from 0. An index that is off by one gives a neighbor of the term you want, and it looks just as plausible.
- Trusting Binet's formula in decimals. Rounding φ to the power n over √5 in double precision first gives a wrong term at n = 71. Use it as a check, not as the method.
- Using floating point for big terms. Ordinary numbers hold whole values exactly only up to 2^53, so every term after F(78) gets rounded. Spreadsheets have the same limit.
- Forgetting that 1 appears twice. F(1) and F(2) are both 1, so "which term is 1?" has two answers. The test reports F(1).
- Calling 144 a coincidence. F(12) = 144 is 12 squared, and it is the only square in the sequence above 1, as J. H. E. Cohn proved in 1964.