The Standard Engine.
MathematicsFinanceHealthPhysicsEngineeringBrowse all

Mathematics · Algebra & Calculus · Sequences & Series

Fibonacci Sequence Calculator

Computes the nth Fibonacci number and generates the Fibonacci sequence up to n terms using Binet's closed-form formula.

Calculator

Advertisement

Formula

F(n) is the nth Fibonacci number (with F(1)=1, F(2)=1). The variable n is the term index (positive integer). The constant phi (φ ≈ 1.6180339887) is the golden ratio, and psi (ψ ≈ −0.6180339887) is its conjugate. As n grows, the psi term becomes negligible, so F(n) is simply the nearest integer to φ^n / √5.

Source: Binet, J.P.M. (1843). Mémoire sur l'intégration des équations linéaires aux différences finies. Comptes Rendus de l'Académie des Sciences, 17, 559–567.

How it works

The Fibonacci sequence is defined by the recurrence relation F(n) = F(n−1) + F(n−2), with seed values F(1) = 1 and F(2) = 1. While this recursive definition is intuitive, computing large terms requires iterating through every previous term — an O(n) operation. Binet's formula, derived in 1843, bypasses this entirely by expressing F(n) as a direct function of n using the golden ratio.

Binet's formula is F(n) = (φⁿ − ψⁿ) / √5, where φ = (1 + √5) / 2 ≈ 1.61803 is the golden ratio and ψ = (1 − √5) / 2 ≈ −0.61803 is its algebraic conjugate. Because |ψ| < 1, the ψⁿ term shrinks toward zero as n increases, meaning F(n) is always the nearest integer to φⁿ / √5. This relationship reveals why consecutive Fibonacci numbers always approximate the golden ratio: as n → ∞, F(n) / F(n−1) → φ.

Fibonacci numbers appear across a remarkable range of real-world domains. In biology, the spiral arrangement of sunflower seeds, pinecone scales, and leaf phyllotaxis follows Fibonacci counts. In computer science, Fibonacci heaps, Fibonacci search algorithms, and pseudorandom number generation all exploit the sequence's properties. In finance, Fibonacci retracement levels (23.6%, 38.2%, 61.8%) are widely used in technical analysis of price charts. In music theory, Fibonacci ratios appear in the proportions of classical compositions.

Worked example

Suppose you want to find the 10th Fibonacci number. Using Binet's formula:

Step 1 — Compute the golden ratio: φ = (1 + √5) / 2 = (1 + 2.2360679…) / 2 = 1.6180339887…

Step 2 — Compute ψ: ψ = (1 − √5) / 2 = (1 − 2.2360679…) / 2 = −0.6180339887…

Step 3 — Raise to the 10th power: φ¹⁰ = 1.6180339887¹⁰ = 122.9918693… and ψ¹⁰ = (−0.6180339887)¹⁰ = 0.0081306…

Step 4 — Subtract and divide by √5: F(10) = (122.9918693 − 0.0081306) / 2.2360679 = 122.9837387 / 2.2360679 = 54.999…

Step 5 — Round to the nearest integer: F(10) = 55. You can verify this by listing the sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55. ✓

As a bonus, the golden ratio approximation at n = 10 is F(10) / F(9) = 55 / 34 = 1.61764…, which is already within 0.024% of the true golden ratio φ ≈ 1.61803.

Limitations & notes

Binet's formula uses floating-point arithmetic, which introduces rounding errors for very large values of n. Most JavaScript environments use 64-bit IEEE 754 double-precision floats, which provide approximately 15–17 significant decimal digits of precision. For n greater than roughly 70–75, the computed result may differ from the true integer Fibonacci number due to accumulated floating-point error — the Math.round() call compensates for this up to a point, but very large n values (n > 78) should be computed using arbitrary-precision integer arithmetic for guaranteed accuracy. Additionally, this calculator is defined only for positive integer values of n ≥ 1; while the Fibonacci sequence can be extended to negative integers using the Negafibonacci extension, that is outside the scope of this tool. Fractional or negative inputs are not supported and will produce unreliable results.

Frequently asked questions

What is the 50th Fibonacci number?

The 50th Fibonacci number is 12,586,269,025. You can verify this using Binet's formula or by iterating the recurrence. At n = 50, the golden ratio approximation F(50) / F(49) = 12,586,269,025 / 7,778,742,049 ≈ 1.6180339887, which matches φ to 10 significant figures.

Why does the ratio of consecutive Fibonacci numbers converge to the golden ratio?

This follows directly from Binet's formula. As n grows large, the ψⁿ term becomes negligible (since |ψ| < 1), so F(n) ≈ φⁿ / √5. Therefore F(n) / F(n−1) ≈ (φⁿ / √5) / (φⁿ⁻¹ / √5) = φ. The convergence is geometric: the error decreases by a factor of |ψ/φ| ≈ 0.382 with each additional term.

Is Fibonacci(0) equal to 0 or 1?

This depends on the indexing convention. The most common convention used in mathematics and this calculator is F(1) = 1, F(2) = 1. An alternative convention, common in computer science (e.g., OEIS A000045), defines F(0) = 0, F(1) = 1, F(2) = 1. Both are valid — they simply shift the index by one. This calculator uses the F(1) = 1 convention.

Can Fibonacci numbers be negative? What are Negafibonacci numbers?

Yes — the Fibonacci sequence can be extended to negative indices using the identity F(−n) = (−1)^(n+1) × F(n). This yields the Negafibonacci sequence: …−8, 5, −3, 2, −1, 1, 0, 1, 1, 2, 3, 5, 8… The absolute values are the same as the standard sequence, but alternate in sign for even negative indices. This calculator does not support negative n.

How are Fibonacci numbers used in algorithm design and computer science?

Fibonacci numbers appear in several important algorithms. Fibonacci search is an efficient comparison-based search algorithm for sorted arrays that uses Fibonacci numbers to divide the search space. Fibonacci heaps are a priority queue data structure that achieves amortized O(1) time for many operations, underpinning fast implementations of Dijkstra's algorithm. The Fibonacci sequence also provides the worst-case input for naive recursive computation, illustrating exponential time complexity without memoization — a classic example used to motivate dynamic programming.

Last updated: 2025-01-15 · Formula verified against primary sources.