Fibonacci Number Calculator
Inputs
| Index | 10 |
|---|
Visualization
Fibonacci Number Calculator
Calculates the nth Fibonacci number, F(n−1), and the ratio F(n)/F(n−1), which converges to the golden ratio φ ≈ 1.61803, along with the full sequence up to n = 70.
Inputs
Results
Enter a value to see results.
Details
What this calculator computes
The Fibonacci Number Calculator finds F(n) — the nth term in the Fibonacci sequence — for any index from 0 to 70. Entering an index n returns the value of F(n), along with F(n−1), the ratio F(n)/F(n−1) (which converges to the golden ratio), and the full sequence from F(0) to F(n).
The Fibonacci sequence
The Fibonacci sequence starts with 0 and 1, and every subsequent term is the sum of the two before it:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …
Formally: F(0) = 0, F(1) = 1, and F(n) = F(n−1) + F(n−2) for n ≥ 2.
The sequence is named after Leonardo of Pisa (c. 1170–1250), known as Fibonacci, who used it to model rabbit population growth in his 1202 book Liber Abaci. However, Indian mathematicians described the same sequence centuries earlier in the context of Sanskrit metre patterns.
How this calculator computes F(n)
The calculator uses an iterative loop rather than the recursive definition. Starting from F(0) = 0 and F(1) = 1, each step computes the next term from the previous two, reaching F(n) in exactly n − 1 additions. This runs in O(n) time and avoids the exponential blowup of naïve recursion.
The maximum supported index is n = 70, because F(70) = 190,392,490,709,135 — the largest Fibonacci number that fits exactly in a 64-bit IEEE 754 double. Beyond n = 70, the values exceed JavaScript's safe-integer boundary (2⁵³ ≈ 9 × 10¹⁵), and floating-point rounding would corrupt the result.
Worked example
Input: n = 12
Step-by-step:
| n | F(n) |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 5 |
| 6 | 8 |
| 7 | 13 |
| 8 | 21 |
| 9 | 34 |
| 10 | 55 |
| 11 | 89 |
| 12 | 144 |
Result: F(12) = 144, F(11) = 89, ratio = 144/89 ≈ 1.61797753.
Note that 144 is itself a perfect square (12²), making it one of only three Fibonacci numbers (along with 0 and 1) that are also perfect squares.
The golden ratio connection
As n increases, the ratio F(n) / F(n−1) converges to the golden ratio:
| n | F(n) | F(n)/F(n−1) |
|---|---|---|
| 5 | 5 | 1.66667 |
| 10 | 55 | 1.61765 |
| 20 | 6765 | 1.61803 |
| 30 | 832040 | 1.61803399 |
By n = 20 the ratio is accurate to six decimal places. The golden ratio appears throughout geometry (the diagonal-to-side ratio of a regular pentagon), art (proportions considered aesthetically pleasing), and natural growth patterns such as the spiral arrangements of seeds in sunflowers and pine cones.
Binet's formula
Binet's formula expresses F(n) directly, without iteration:
where is the golden ratio and is its conjugate.
Because |ψ| < 1, the term ψⁿ shrinks toward zero as n grows. For n ≥ 1, this means F(n) is simply the nearest integer to . While elegant, Binet's formula relies on floating-point arithmetic and loses precision for large n, which is why this calculator uses the iterative approach for exact results.
Fibonacci numbers in nature and science
The sequence turns up in surprisingly diverse places:
- Botany: Many flowering plants produce petals in Fibonacci numbers — typically 3, 5, 8, or 13. Sunflower seed heads typically have 34 and 55 spiral rows.
- Phyllotaxis: Leaves and branches often grow at angles related to φ, spacing them to maximise sunlight.
- Computer science: Fibonacci heaps, a data structure used in graph algorithms, take their name from the sequence. The worst-case tree structure of naïve recursive Fibonacci computation illustrates exponential time complexity.
- Finance: Fibonacci retracement levels (23.6%, 38.2%, 61.8%) — derived from ratios of consecutive terms — are widely used in technical analysis, though their predictive value is debated.
Frequently Asked Questions (FAQ)
What is the Fibonacci sequence?
The Fibonacci sequence is a series of numbers where each term is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … Formally, F(0) = 0, F(1) = 1, and F(n) = F(n−1) + F(n−2) for n ≥ 2. The sequence is named after the 13th-century Italian mathematician Leonardo of Pisa, known as Fibonacci, though it was described in Indian mathematics centuries earlier.
How does the Fibonacci sequence relate to the golden ratio?
As n grows, the ratio of consecutive Fibonacci numbers F(n) / F(n−1) converges to the golden ratio φ = (1 + √5) / 2 ≈ 1.6180339887. By n = 10 the ratio is already 1.61764706, and by n = 20 it is accurate to six decimal places. This connection appears throughout art, architecture, and nature — for example in the spiral arrangements of seeds in sunflowers and the branching of trees.
What is Binet's formula?
Binet's formula gives F(n) directly without iteration: F(n) = (φⁿ − ψⁿ) / √5, where φ = (1 + √5) / 2 ≈ 1.61803 is the golden ratio and ψ = (1 − √5) / 2 ≈ −0.61803 is its conjugate. For large n, ψⁿ is tiny, so F(n) is the nearest integer to φⁿ / √5. The formula is elegant but uses floating-point arithmetic, so for exact integer values an iterative computation (as used here) is more reliable.
How large can n be in this calculator?
This calculator supports n from 0 to 70. F(70) = 190,392,490,709,135, which is the largest Fibonacci number that fits exactly in a JavaScript 64-bit double without precision loss. F(71) and beyond exceed 2⁵³ = 9,007,199,254,740,992 (the safe-integer boundary for IEEE 754), so the calculator caps n at 70 to guarantee exact results.
Recommended Next
Factorial Calculator
Calculate n! for any integer from 0 to 20. See exact results up to 20! = 2,432,902,008,176,640,000.