Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

Fibonacci Sequence Calculator






What is the Fibonacci Sequence?

The Fibonacci sequence is defined by the linear recurrence

Fn=Fn1+Fn2F_n = F_{n-1} + F_{n-2}


with initial conditions F1=F2=1F_1 = F_2 = 1. The first terms are:

1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, \ldots


Each term is the sum of the two before. Despite the simplicity of the rule, the sequence has profound connections to algebra, geometry, number theory, and the natural world.

Historical origin. Named after Leonardo Fibonacci of Pisa, who introduced the sequence to Western mathematics in his 1202 book Liber Abaci through a problem about rabbit populations. The sequence was known earlier in Indian mathematics, particularly in Sanskrit prosody.

Index conventions. This explorer uses F1=F2=1F_1 = F_2 = 1. Other conventions start at F0=0,F1=1F_0 = 0, F_1 = 1 (giving the same sequence shifted by one). Be careful when comparing references.

Exact computation. Fibonacci numbers grow exponentially — F100F_{100} has 21 digits, F1000F_{1000} has 209 digits. The explorer uses arbitrary-precision integers (BigInt) so every term is exact at any index, with no floating-point error.

For deeper coverage see Fibonacci sequence, golden ratio, and linear recurrence.

The Recurrence and Binet's Formula

The recurrence. Fn=Fn1+Fn2F_n = F_{n-1} + F_{n-2} is a second-order linear recurrence with constant coefficients. Its characteristic equation is

x2=x+1x^2 = x + 1


with roots

φ=1+521.61803398,ψ=1520.61803398\varphi = \frac{1 + \sqrt{5}}{2} \approx 1.61803398\ldots, \quad \psi = \frac{1 - \sqrt{5}}{2} \approx -0.61803398\ldots


φ\varphi is the golden ratio.

Binet's formula. The closed-form expression for FnF_n is

Fn=φnψn5F_n = \frac{\varphi^n - \psi^n}{\sqrt{5}}


Since ψ<1|\psi| < 1, ψn\psi^n shrinks rapidly to zero, and FnF_n is well-approximated by φn/5\varphi^n / \sqrt{5} for large nn.

Why the formula gives an integer. φ\varphi and ψ\psi are irrational, but the combination φnψn\varphi^n - \psi^n always lies in 5Z\sqrt{5} \mathbb{Z} — the difference of conjugate irrational powers cancels into a rational multiple of 5\sqrt{5}. Dividing by 5\sqrt{5} gives an integer.

Practical computation. Binet's formula has floating-point limitations: for large nn, the formula needs more precision than typical doubles provide. The recurrence (or matrix exponentiation, or fast doubling) is preferred for exact computation, which is why this explorer uses BigInt iteration.

Matrix form. (Fn+1Fn)=(1110)n(10)\begin{pmatrix} F_{n+1} \\ F_n \end{pmatrix} = \begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}^n \begin{pmatrix} 1 \\ 0 \end{pmatrix}. Matrix exponentiation by repeated squaring computes FnF_n in O(logn)O(\log n) multiplications.

The Membership Test — Gessel's Identity

Given a positive integer mm, how do you decide whether mm is a Fibonacci number?

Gessel's identity (1972). mm is a Fibonacci number if and only if

5m2+4or5m245 m^2 + 4 \quad \text{or} \quad 5 m^2 - 4


is a perfect square. Once one of these is a perfect square, the index nn is found by iterating the Fibonacci recurrence until Fn=mF_n = m.

Why two cases. The identity has both +4+4 and 4-4 because Fibonacci numbers at even and odd indexes behave differently with respect to the underlying Lucas-Fibonacci identity. Specifically:

5Fn2+4=Ln2+4Ln45 F_n^2 + 4 = L_n^2 + 4 L_n - 4 — wait, the cleaner statement: 5Fn24(1)n=Ln25 F_n^2 - 4 (-1)^n = L_n^2, where LnL_n is the nn-th Lucas number.

So 5Fn2+45 F_n^2 + 4 is a perfect square (equal to Ln2L_n^2) when nn is odd, and 5Fn245 F_n^2 - 4 is a perfect square when nn is even. Together, the two cases cover all Fibonacci numbers.

Example. Is 144 Fibonacci? Compute 51442=1036805 \cdot 144^2 = 103680. Then 103680+4=103684103680 + 4 = 103684; 103684321.99\sqrt{103684} \approx 321.99\ldots, not a perfect square. Try 1036804=103676103680 - 4 = 103676; 103676=322\sqrt{103676} = 322, a perfect square. So 144 is Fibonacci. Iterating the recurrence: 1,1,2,3,5,8,13,21,34,55,89,1441, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 — that's F12F_{12}. So 144=F12144 = F_{12}.

Non-example. Is 100 Fibonacci? 51002=500005 \cdot 100^2 = 50000. Then 50000+4=5000450000 + 4 = 50004; 50004223.61\sqrt{50004} \approx 223.61, not a perfect square. 500004=4999650000 - 4 = 49996; 49996223.59\sqrt{49996} \approx 223.59, not a perfect square either. So 100 is not Fibonacci. The nearest are F11=89F_{11} = 89 and F12=144F_{12} = 144.

BigInt arithmetic. For large mm, the squares 5m2±45 m^2 \pm 4 exceed safe-integer precision. The explorer uses BigInt for these checks, so the test is exact for any input within input-parsing range.

Properties and Identities

Fibonacci numbers satisfy hundreds of identities. A representative selection:

Cassini's identity: Fn1Fn+1Fn2=(1)nF_{n-1} F_{n+1} - F_n^2 = (-1)^n. The product of two terms straddling FnF_n differs from Fn2F_n^2 by exactly ±1\pm 1.
Catalan's identity: Fn2FnrFn+r=(1)nrFr2F_n^2 - F_{n-r} F_{n+r} = (-1)^{n-r} F_r^2. A generalization of Cassini's.
d'Ocagne's identity: FmFn+1Fm+1Fn=(1)nFmnF_m F_{n+1} - F_{m+1} F_n = (-1)^n F_{m-n}.
Fast doubling: F2n=Fn(2Fn+1Fn)F_{2n} = F_n (2 F_{n+1} - F_n) and F2n+1=Fn2+Fn+12F_{2n+1} = F_n^2 + F_{n+1}^2. These give O(logn)O(\log n) computation by recursion.
Sum identity: F1+F2++Fn=Fn+21F_1 + F_2 + \cdots + F_n = F_{n+2} - 1.
Sum of squares: F12+F22++Fn2=FnFn+1F_1^2 + F_2^2 + \cdots + F_n^2 = F_n F_{n+1}.
Sum of odd-indexed: F1+F3+F5++F2n1=F2nF_1 + F_3 + F_5 + \cdots + F_{2n-1} = F_{2n}.
GCD identity: gcd(Fm,Fn)=Fgcd(m,n)\gcd(F_m, F_n) = F_{\gcd(m, n)}. A beautiful number-theoretic property — the GCD of Fibonacci numbers is itself a Fibonacci number.
Divisibility: FmFnF_m \mid F_n if and only if mnm \mid n (for m3m \geq 3). Fibonacci-number divisibility mirrors index divisibility.
Zeckendorf's theorem: every positive integer has a unique representation as a sum of non-consecutive Fibonacci numbers.

Fibonacci in Nature and Application

Fibonacci numbers appear with striking frequency in biological and physical contexts.

Phyllotaxis. The arrangement of leaves around a stem, seeds in a sunflower, scales on a pinecone, and bracts on a pineapple often follows Fibonacci-based spirals. A sunflower head typically has 34 spirals in one direction and 55 in the other (both Fibonacci numbers). The golden angle 137.5°\approx 137.5°, derived from φ\varphi, is the optimal packing angle.

Branching patterns. Some tree species (notably elm and rose) produce branches in counts that grow by Fibonacci numbers.

Pinecone and pineapple spirals. Pinecones have spiral counts in pairs like (5, 8), (8, 13), or (13, 21) — consecutive Fibonacci numbers.

Honeybee genealogy. Male bees (drones) have only one parent; female bees have two. Counting ancestors back, a drone's ancestor counts form the Fibonacci sequence: 1, 1, 2, 3, 5, ...

Cryptography and algorithms. Fibonacci heaps achieve O(1)O(1) amortized insertion, and Fibonacci coding is used in some data-compression schemes.

Financial markets. Some traders use Fibonacci retracements (38.2%, 50%, 61.8%) derived from Fibonacci ratios for technical analysis. The mathematical basis is more cultural than rigorous.

Counting compositions. Fn+1F_{n+1} counts the ways to write nn as an ordered sum of 1s and 2s — closely related to tiling and combinatorial problems.

Art and architecture. The golden ratio and Fibonacci proportions appear in classical Greek architecture, Renaissance art, and modern design. Some claims are exaggerated; others are well-documented.

Fibonacci and the Golden Ratio

The golden ratio φ=(1+5)/21.618\varphi = (1 + \sqrt{5})/2 \approx 1.618 is the key analytic object behind the Fibonacci sequence.

Limit of ratios. As nn \to \infty:

limnFn+1Fn=φ\lim_{n \to \infty} \frac{F_{n+1}}{F_n} = \varphi


Even for modest nn, the ratio is close to φ\varphi: F11/F10=89/55=1.61818F_{11}/F_{10} = 89/55 = 1.61818\ldots.

Why phi. φ\varphi is the unique positive number satisfying φ=1+1/φ\varphi = 1 + 1/\varphi, equivalently φ2=φ+1\varphi^2 = \varphi + 1. This equation matches the structure of the Fibonacci recurrence. Solving x2x1=0x^2 - x - 1 = 0 gives φ\varphi and ψ=(15)/2\psi = (1 - \sqrt{5})/2.

The golden ratio's role in Binet's formula. Fn=(φnψn)/5F_n = (\varphi^n - \psi^n)/\sqrt{5}. Since ψ<1|\psi| < 1, the ψn\psi^n term decays, and Fnφn/5F_n \approx \varphi^n / \sqrt{5} to within 1/21/2 for all n1n \geq 1.

The golden rectangle. A rectangle with side ratio φ:1\varphi : 1 has the property that cutting off a square leaves a smaller rectangle with the same side ratio. Drawing diagonals of these nested rectangles approximates the logarithmic spiral, which itself is closely related to natural growth patterns.

Other irrational appearances. The continued-fraction expansion of φ\varphi is [1;1,1,1,][1; 1, 1, 1, \ldots] — the simplest possible continued fraction. This makes φ\varphi the most irrational number in the sense of being hardest to approximate by rationals.

Common Mistakes

Index convention confusion. Two common conventions: F0=0,F1=1F_0 = 0, F_1 = 1 (Knuth, OEIS) or F1=F2=1F_1 = F_2 = 1 (this explorer, many classical references). They give the same sequence shifted by one. Always check the convention before quoting a value.

Floating-point precision errors. Binet's formula or naive double-precision computation breaks at moderate nn. F80F_{80} already has 17 digits — exceeding double precision. Use BigInt or symbolic computation for exact values.

Misapplying Gessel's identity. Both 5m2+45m^2 + 4 and 5m245m^2 - 4 must be checked; only one will be a perfect square (or neither, if mm is not Fibonacci). Skipping one case incorrectly rejects half of all Fibonacci numbers.

Naive recursive computation. Computing FnF_n via the naive recursion fib(n)=fib(n1)+fib(n2)\text{fib}(n) = \text{fib}(n-1) + \text{fib}(n-2) has exponential time complexity. Use memoization, iteration, fast doubling, or matrix exponentiation for O(n)O(n) or O(logn)O(\log n).

Confusing Fibonacci with Lucas numbers. Lucas numbers LnL_n satisfy the same recurrence with L1=1,L2=3L_1 = 1, L_2 = 3. They share many identities with Fibonacci but are a distinct sequence: 1, 3, 4, 7, 11, 18, 29, 47, ...

Overclaiming nature appearances. Fibonacci spirals appear in many plants but not all. Spurious claims (e.g., "the Mona Lisa uses golden-ratio proportions") are common but often unsupported by careful measurement.

Related Sequences and Concepts

Lucas NumbersLn=Ln1+Ln2L_n = L_{n-1} + L_{n-2} with L1=1,L2=3L_1 = 1, L_2 = 3. Closely related to Fibonacci; share many identities. Sequence: 1, 3, 4, 7, 11, 18, 29, 47, ...

Golden Ratioφ=(1+5)/2\varphi = (1 + \sqrt{5})/2. The limit of consecutive Fibonacci ratios; appears in Binet's formula.

Tribonacci Numbers — the three-term generalization: Tn=Tn1+Tn2+Tn3T_n = T_{n-1} + T_{n-2} + T_{n-3}. Each term is the sum of the previous three.

Pell NumbersPn=2Pn1+Pn2P_n = 2 P_{n-1} + P_{n-2} with P0=0,P1=1P_0 = 0, P_1 = 1. Closely related to 2\sqrt{2} as Fibonacci is to φ\varphi.

Binet's Formula — the closed-form expression for FnF_n using φ\varphi and ψ\psi. The prototype for closed-form solutions of linear recurrences.

Linear Recurrence — the general class. Fibonacci is the simplest non-trivial second-order linear recurrence.

Generating FunctionFnxn=x/(1xx2)\sum F_n x^n = x/(1 - x - x^2). The rational generating function corresponds to a linear recurrence.

Continued Fractions — convergents of φ\varphi are exactly Fn+1/FnF_{n+1}/F_n. Connects irrational approximation to Fibonacci.

Zeckendorf Representation — every positive integer has a unique decomposition as a sum of non-consecutive Fibonacci numbers. A base-φ\varphi analog of binary representation.

Lucas Sequence — a two-parameter family generalizing Fibonacci. Defined by recurrence Un=PUn1QUn2U_n = P U_{n-1} - Q U_{n-2}. Fibonacci is Un(P=1,Q=1)U_n(P = 1, Q = -1).

Pisano Period — the period of Fibonacci numbers modulo mm, denoted π(m)\pi(m). The sequence Fn(modm)F_n \pmod m is always periodic; the period has interesting number-theoretic properties.

Wythoff Sequences — pairs of sequences whose union is all positive integers, defined using φ\varphi. The "lower" Wythoff sequence is nφ\lfloor n \varphi \rfloor and the "upper" is nφ2\lfloor n \varphi^2 \rfloor.

Spiral and Phyllotaxis — the natural appearance of Fibonacci numbers in plant arrangements, sunflower seed spirals, pinecone scales, etc.