Fibonacci Calculator
Find the nth Fibonacci number and display the Fibonacci sequence up to that term. This free online math calculator gives you instant step-by-step results.
What Is the Fibonacci Sequence?
The Fibonacci sequence is one of the most famous number patterns in mathematics. It is defined by a simple recurrence relation: each number is the sum of the two preceding numbers. The classical sequence (1-indexed) begins: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584 …
Formally: F(1) = 1, F(2) = 1, F(n) = F(n−1) + F(n−2) for all n > 2. An alternate convention starts with F(0) = 0, F(1) = 1, shifting the index by one. Both are valid; this calculator uses the 1-indexed (classical) convention.
The sequence is named after Leonardo of Pisa, known as Fibonacci, who introduced it to Western mathematics in his 1202 book Liber Abaci (Book of Calculation). He used it to model idealized rabbit population growth: start with one pair, each pair produces one new pair each month after a one-month maturation period, and rabbits never die. After n months, you have F(n) pairs. This was a pedagogical example, not a realistic ecological model — but it launched one of the most studied sequences in all of mathematics.
Fibonacci Sequence Table: First 30 Terms
Here are the first 30 Fibonacci numbers for quick reference. Notice how quickly the values grow — this is characteristic of exponential-like growth.
| n | F(n) | n | F(n) | n | F(n) |
|---|---|---|---|---|---|
| 1 | 1 | 11 | 89 | 21 | 10,946 |
| 2 | 1 | 12 | 144 | 22 | 17,711 |
| 3 | 2 | 13 | 233 | 23 | 28,657 |
| 4 | 3 | 14 | 377 | 24 | 46,368 |
| 5 | 5 | 15 | 610 | 25 | 75,025 |
| 6 | 8 | 16 | 987 | 26 | 121,393 |
| 7 | 13 | 17 | 1,597 | 27 | 196,418 |
| 8 | 21 | 18 | 2,584 | 28 | 317,811 |
| 9 | 34 | 19 | 4,181 | 29 | 514,229 |
| 10 | 55 | 20 | 6,765 | 30 | 832,040 |
F(50) = 12,586,269,025. F(100) = 354,224,848,179,261,915,075. These numbers grow approximately as φⁿ/√5, where φ = (1+√5)/2 ≈ 1.618 (the golden ratio). The ratio of consecutive Fibonacci numbers converges to φ: F(21)/F(20) = 10946/6765 ≈ 1.61803...
The Golden Ratio and Fibonacci Numbers
The golden ratio φ (phi) = (1 + √5)/2 ≈ 1.6180339887... is the limit of the ratio F(n+1)/F(n) as n approaches infinity. This connection is one of the most beautiful relationships in mathematics — a simple integer sequence converges to an irrational constant that appears throughout geometry, art, and nature.
Binet's closed-form formula gives the nth Fibonacci number directly without recursion:
F(n) = (φⁿ − ψⁿ) / √5, where ψ = (1−√5)/2 ≈ −0.618
Since |ψ| < 1, the term ψⁿ/√5 becomes negligible for large n, meaning F(n) ≈ φⁿ/√5 rounded to the nearest integer. For n = 10: φ¹⁰/√5 = 55.0036... → rounds to 55. ✓
The golden ratio appears in:
- Golden rectangles: a rectangle with aspect ratio φ:1 can be divided into a square and a smaller golden rectangle, indefinitely
- Golden spiral: the curve connecting corners of successively smaller golden rectangles, approximated by drawing quarter-circles through Fibonacci squares
- Pentagon and pentagram: the diagonals of a regular pentagon divide each other in the golden ratio
- Icosahedron: the 12 vertices of a regular icosahedron form three mutually perpendicular golden rectangles
Fibonacci Numbers in Nature
Fibonacci numbers appear with striking frequency in natural growth patterns. This is not coincidence — these patterns emerge from the mathematics of efficient packing and continuous growth.
| Natural Pattern | Fibonacci Connection | Example Values |
|---|---|---|
| Flower petals | Most flowers have F(n) petals | Buttercup: 5, Delphinium: 8, Marigold: 13, Daisy: 21 or 34 |
| Sunflower seed spirals | Clockwise and counterclockwise spiral counts are consecutive Fibonacci numbers | Typically 34 and 55, or 55 and 89 |
| Pine cone spirals | Two sets of spirals in Fibonacci numbers | 5 and 8, or 8 and 13 |
| Pineapple scales | Three sets of spirals | 5, 8, and 13 |
| Leaf arrangement (phyllotaxis) | Leaves grow at golden angle (137.5°) apart | Maximizes sunlight exposure |
| Romanesco broccoli | Self-similar spiral structure with Fibonacci counts | Visible fractal Fibonacci spirals |
| Nautilus shell | Logarithmic spiral approximating golden spiral | Growth ratio ≈ φ per quarter-turn |
The golden angle — 360° × (1 − 1/φ) ≈ 137.5° — is the angle between successive leaf or seed primordia in optimal phyllotaxis. Growing a new leaf at 137.5° from the previous one means no two leaves are ever at the same angle, maximizing access to sunlight and rain. This optimal angle is determined by the golden ratio, which is determined by Fibonacci numbers. Nature evolves toward mathematical efficiency.
Fibonacci Numbers in Computer Science
The Fibonacci sequence is foundational in computer science education and algorithm design. The naive recursive implementation is the canonical example of exponential time complexity and the power of memoization.
Naive recursion (bad): fib(n) = fib(n-1) + fib(n-2). This computes fib(n-2) many redundant times. Computing fib(50) requires over 10¹² function calls — billions of redundant computations. Time complexity: O(2ⁿ).
Dynamic programming (good): Store previously computed values. Computing fib(n) requires exactly n−1 additions. Time complexity: O(n), space: O(n) or O(1) with rolling variables.
Matrix exponentiation (best for huge n): The identity [F(n+1), F(n); F(n), F(n-1)] = [1,1;1,0]ⁿ allows computing F(n) in O(log n) time using fast matrix exponentiation. This is essential for competitive programming problems like "find F(10¹⁸) mod 10⁹+7."
Fibonacci numbers also appear in:
- Fibonacci heaps: a priority queue data structure with optimal amortized time bounds for decrease-key operations, used in Dijkstra's algorithm
- Fibonacci search: a divide-and-conquer search algorithm similar to binary search but using Fibonacci numbers to split arrays, requiring no division operations
- Zeckendorf's representation: every positive integer can be uniquely expressed as a sum of non-consecutive Fibonacci numbers (e.g., 11 = 8 + 3, not 8 + 2 + 1)
- Fibonacci coding: a universal code using Fibonacci representations, used in data compression
Divisibility Properties and Number Theory
Fibonacci numbers have remarkable number-theoretic properties that make them useful in cryptography and mathematical research:
- GCD property: GCD(F(m), F(n)) = F(GCD(m, n)). This means Fibonacci numbers share common factors only when their indices share common factors.
- Divisibility: F(m) divides F(n) if and only if m divides n. So F(5) = 5 divides F(10) = 55, F(15) = 610, F(20) = 6765, etc.
- Pisano periods: F(n) mod m is periodic for any modulus m. For m=10 (last digit), the period is 60. For m=100 (last two digits), the period is 300. These allow finding the last k digits of F(n) without computing the full number.
- Prime Fibonacci numbers: A Fibonacci number F(n) can only be prime if n itself is prime (with the exception of F(4) = 3). Known Fibonacci primes include F(3)=2, F(4)=3, F(5)=5, F(7)=13, F(11)=89, F(13)=233... Whether there are infinitely many Fibonacci primes is an open problem.
- Every 3rd Fibonacci number is even: F(3)=2, F(6)=8, F(9)=34, F(12)=144... Every 4th is divisible by 3, every 5th by 5 (note: F(5)=5), and so on — each Fibonacci number F(k) divides every kth subsequent Fibonacci number.
Historical Background and Cultural Significance
The sequence now known as Fibonacci numbers was first described in Indian mathematics. The Sanskrit scholar Pingala (c. 300–200 BC) studied the combinatorics of Sanskrit poetry, specifically the number of ways to arrange long (2-beat) and short (1-beat) syllables to fill a verse of n beats. His analysis yielded the Fibonacci numbers implicitly. The mathematician Virahanka (c. 600–800 AD) and later Hemachandra (1150 AD) described the sequence explicitly in the context of Hindi poetry meter.
In Europe, Leonardo of Pisa (Fibonacci) introduced the sequence in Liber Abaci (1202) using the rabbit population problem. More importantly, this book introduced Hindu-Arabic numerals (0-9) to Europe, replacing the cumbersome Roman numeral system. Fibonacci's contribution to mathematics extends far beyond his famous sequence — he revolutionized European arithmetic and made the development of algebra and calculus possible.
The connection to the golden ratio was formalized by mathematicians in the 16th and 17th centuries. Johannes Kepler noted that consecutive Fibonacci numbers approach the golden ratio. The sequence received its modern name in 1877 when French mathematician Édouard Lucas (who also gave us the related Lucas numbers: 2, 1, 3, 4, 7, 11, 18, 29...) named them after Fibonacci.
Fibonacci Numbers in Finance and Trading
Technical analysts in financial markets use Fibonacci ratios to identify potential support and resistance levels. "Fibonacci retracements" are horizontal lines at key levels derived from the Fibonacci sequence:
| Fibonacci Level | Calculation | Interpretation |
|---|---|---|
| 23.6% | F(n)/F(n+3) → 1/φ³ | Shallow retracement level |
| 38.2% | F(n)/F(n+2) → 1/φ² | Common support/resistance |
| 50.0% | Not strictly Fibonacci | Psychological midpoint |
| 61.8% | F(n)/F(n+1) → 1/φ | The "golden ratio" level |
| 78.6% | √(61.8%) | Deep retracement level |
Whether Fibonacci levels have genuine predictive power in markets is debated among academics — many studies suggest they perform no better than random levels. However, their widespread use creates self-fulfilling prophecies: because many traders watch these levels, price reactions at them become more likely. The mathematics is elegant; the trading application is psychological as much as mathematical.
Frequently Asked Questions
What is F(1) — does the Fibonacci sequence start at 0 or 1?
This calculator uses the classical convention: F(1)=1, F(2)=1. Some sources use the extended convention: F(0)=0, F(1)=1. Both give the same values for F(n) when n≥1; they differ only in how n is counted. The 0-indexed version is convenient in computer science (zero-based arrays), while the 1-indexed version reflects the original historical formulation.
What is the 50th Fibonacci number?
F(50) = 12,586,269,025. The sequence grows approximately as φⁿ/√5, where φ ≈ 1.618. Since φ¹⁰ ≈ 122.99, the numbers roughly multiply by 122-123 every 10 steps: F(50) ≈ F(40) × 123 ≈ 102,334,155 × 123 ≈ 12.6 billion.
Why do Fibonacci numbers appear in nature?
Fibonacci phyllotaxis arises because growing organs (leaves, seeds, petals) form sequentially, each at the golden angle (≈137.5°) from the previous one. The golden angle is the only angle that never produces a "spoke" pattern — it maximizes the number of distinct radial directions, which maximizes light and nutrient access. The connection to Fibonacci numbers comes from the fact that the golden ratio is the most "irrational" number, meaning it converges slowest when expressed as a continued fraction, ensuring optimal angular spacing.
Is the Fibonacci sequence the same as the Lucas sequence?
No, but they are closely related. The Lucas sequence uses the same recurrence relation (L(n) = L(n-1) + L(n-2)) but starts with L(1)=1, L(2)=3: 1, 3, 4, 7, 11, 18, 29, 47... The ratio of consecutive Lucas numbers also converges to φ. They satisfy: L(n) = F(n-1) + F(n+1) and F(2n) = F(n)·L(n).
What is Binet's formula?
Binet's formula gives the nth Fibonacci number directly: F(n) = (φⁿ − ψⁿ)/√5, where φ = (1+√5)/2 ≈ 1.618 and ψ = (1−√5)/2 ≈ −0.618. Since |ψ| < 1, ψⁿ→0 as n→∞, so F(n) is the nearest integer to φⁿ/√5 for all n≥1. This formula converts a recursive definition into a closed-form (direct calculation) formula.
Are there Fibonacci numbers in Pascal's triangle?
Yes! If you sum the shallow diagonals of Pascal's triangle (going from bottom-left to top-right), the sums are Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13... This is one of many surprising connections between Fibonacci numbers and other areas of combinatorics.
What is the Pisano period?
The Pisano period π(m) is the period with which Fibonacci numbers repeat modulo m. π(10) = 60 (last digit repeats every 60 terms), π(100) = 300 (last two digits repeat every 300 terms). Pisano periods allow computing F(n) mod m for astronomically large n efficiently, important in cryptographic applications.
Can Fibonacci numbers be negative?
The sequence can be extended to negative indices: F(-n) = (-1)^(n+1) × F(n). So F(-1)=1, F(-2)=-1, F(-3)=2, F(-4)=-3, F(-5)=5... The absolute values are the same Fibonacci numbers, with alternating signs for even negative indices. This extension, called the negafibonacci sequence, maintains the recurrence relation.
How large can this calculator compute?
This calculator works up to F(80) = 23,416,728,348,161,557,424 using standard JavaScript floating-point arithmetic. For larger values, JavaScript's number precision is insufficient without special big-integer libraries. For exact values of F(n) for large n, use Python's arbitrary-precision integers or a specialized big number library.
What is Zeckendorf's theorem?
Every positive integer has a unique representation as a sum of non-consecutive Fibonacci numbers. For example: 10 = 8 + 2 = F(6) + F(3); 11 = 8 + 3 = F(6) + F(4); 20 = 13 + 5 + 2 = F(7) + F(5) + F(3). No two adjacent Fibonacci numbers appear in the sum. This is Zeckendorf's representation and has applications in data compression (Fibonacci coding).
Fibonacci Sequence and Music Theory
Surprisingly, Fibonacci numbers appear in music theory and composition. The musical scale contains 13 notes from an octave to the next; an octave spans 8 notes; a chord is built on the 1st, 3rd, and 5th notes of a scale (positions 1, 3, 5 — all Fibonacci numbers). An octave contains 5 whole-tone and 2 semitone black keys on a piano keyboard, in a pattern of 2 and 3 (consecutive Fibonacci numbers).
Several composers have deliberately used Fibonacci structure in their works. Béla Bartók's "Music for Strings, Percussion and Celesta" (1936) has structural proportions reflecting Fibonacci numbers. Debussy and Satie used Golden Section proportions in determining climax points in their compositions. Whether these were conscious decisions or post-hoc analysis is debated, but the mathematical structure in music is real and beautiful.
In contemporary music, Fibonacci rhythms appear in progressive rock (Tool's "Lateralus" is famously structured around Fibonacci numbers in syllable counts), electronic music, and experimental composition. The sequence provides a natural way to create rhythmic complexity that feels organic rather than arbitrary.
Fibonacci Identities and Useful Formulas
The Fibonacci sequence has hundreds of known identities. Here are the most useful for calculations:
| Identity | Formula | Example |
|---|---|---|
| Cassini's identity | F(n+1)·F(n-1) − F(n)² = (-1)ⁿ | F(4)·F(2) − F(3)² = 3·1 − 4 = -1 |
| Sum of first n terms | Σ F(i) for i=1..n = F(n+2) − 1 | 1+1+2+3+5=12 = F(7)−1 = 13−1 ✓ |
| Sum of squares | Σ F(i)² for i=1..n = F(n)·F(n+1) | 1+1+4+9+25=40 = F(5)·F(6) = 5·8 ✓ |
| Even-indexed terms | F(2n) = F(n)·(2F(n+1) − F(n)) | F(6) = F(3)·(2F(4) − F(3)) = 2·(6−2) = 8 ✓ |
| Doubling formula | F(2n+1) = F(n)² + F(n+1)² | F(7) = F(3)²+F(4)² = 4+9 = 13 ✓ |
These identities are invaluable in competitive programming, where computing Fibonacci numbers modulo a prime often requires fast exponentiation using the matrix or doubling method rather than simple iteration. The doubling method computes F(2n) and F(2n+1) from F(n) and F(n+1), halving the number of required operations at each step.