Fibonacci Calculator
Nth Fibonacci Number
—
Sequence
—
Golden Ratio Approximation
—
How the Fibonacci Sequence Works
The Fibonacci sequence is a series of numbers where each number equals the sum of the two preceding ones, starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, and so on to infinity. According to the Wolfram MathWorld encyclopedia, the Fibonacci sequence is one of the most widely studied sequences in all of mathematics, with connections to number theory, geometry, biology, art, and financial analysis. Named after the Italian mathematician Leonardo of Pisa (known as Fibonacci), who introduced it to Western mathematics in his 1202 book Liber Abaci, the sequence was actually known to Indian mathematicians centuries earlier, with references appearing in the works of Pingala, Virahanka, and Hemachandra.
In Liber Abaci, Fibonacci posed the question as a model for rabbit population growth: starting with one pair of newborn rabbits, assuming each pair produces one new pair every month beginning in their second month, and no rabbits die, how many pairs are there after n months? The answer follows the Fibonacci sequence exactly. While the biological model is idealized, the mathematical structure it revealed has proven extraordinary versatile, appearing in contexts from scientific computing to stock market analysis. Our calculator lets you generate any number of terms, find the nth Fibonacci number, and see how the ratio of consecutive terms converges to the golden ratio.
The Fibonacci Formula: How It Is Calculated
The recursive definition is: F(n) = F(n-1) + F(n-2), with seed values F(0) = 0 and F(1) = 1. For direct computation without iteration, Binet's formula provides: F(n) = (phi^n - psi^n) / sqrt(5), where phi = (1 + sqrt(5))/2 (the golden ratio, approximately 1.618034) and psi = (1 - sqrt(5))/2 (approximately -0.618034).
Worked example: To find F(10), use Binet's formula: F(10) = (1.618034^10 - (-0.618034)^10) / 2.23607 = (122.9919 - 0.0081) / 2.23607 = 122.9838 / 2.23607 = 55.0000. Rounding gives F(10) = 55. You can verify: the sequence up to the 10th term is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55. For practical computation, the matrix exponentiation method [[1,1],[1,0]]^n computes F(n) in O(log n) time, which is faster than O(n) iteration for very large values. You can explore related sequences with our factorial calculator.
Key Terms You Should Know
- Golden Ratio (phi): The irrational number approximately equal to 1.6180339887, defined as (1 + sqrt(5))/2. The ratio of consecutive Fibonacci numbers converges to phi as n increases. It is sometimes called the divine proportion.
- Binet's Formula: A closed-form expression that computes the nth Fibonacci number directly without iteration, using the golden ratio and its conjugate. Named after French mathematician Jacques Philippe Marie Binet, though known earlier to Euler and de Moivre.
- Phyllotaxis: The study of how leaves, seeds, and petals are arranged on plants. Fibonacci numbers appear in phyllotactic patterns because plants grow new organs at angles related to the golden ratio (the golden angle of approximately 137.5 degrees).
- Fibonacci Retracement: A technical analysis tool used in financial trading that identifies potential support and resistance levels at percentages derived from Fibonacci ratios: 23.6%, 38.2%, 50%, 61.8%, and 78.6%.
- Cassini's Identity: A fundamental Fibonacci identity stating F(n-1) x F(n+1) - F(n)^2 = (-1)^n, meaning the product of neighboring Fibonacci numbers minus the square of the middle term alternates between +1 and -1.
- Zeckendorf Representation: The theorem that every positive integer can be uniquely written as a sum of non-consecutive Fibonacci numbers, forming the basis for Fibonacci coding in data compression.
Fibonacci Numbers: Quick Reference Table
The table below lists the first 25 Fibonacci numbers along with the ratio of consecutive terms, showing the convergence toward the golden ratio. Data sourced from the On-Line Encyclopedia of Integer Sequences (OEIS A000045).
| n | F(n) | F(n)/F(n-1) | Digits |
|---|---|---|---|
| 1 | 1 | -- | 1 |
| 2 | 1 | 1.000000 | 1 |
| 5 | 5 | 1.666667 | 1 |
| 10 | 55 | 1.617647 | 2 |
| 15 | 610 | 1.618056 | 3 |
| 20 | 6,765 | 1.618033 | 4 |
| 25 | 75,025 | 1.618034 | 5 |
| 30 | 832,040 | 1.618034 | 6 |
| 40 | 102,334,155 | 1.618034 | 9 |
| 50 | 12,586,269,025 | 1.618034 | 11 |
Practical Examples
Example 1: Nature -- Sunflower Seed Spirals. A sunflower head typically displays 34 spirals in one direction and 55 in the other (both Fibonacci numbers, F(9) and F(10)). The ratio 55/34 = 1.6176, which approximates the golden ratio. This arrangement maximizes seed packing efficiency because each seed is placed at the golden angle (approximately 137.5 degrees) from the previous one, ensuring no two seeds overlap and every gap is filled optimally.
Example 2: Finance -- Fibonacci Retracement. A stock rises from $100 to $200. A trader draws Fibonacci retracement levels to identify potential pullback support: 23.6% at $176.40, 38.2% at $161.80, 50% at $150.00, and 61.8% at $138.20. If the stock pulls back and finds support near $161.80 (the 38.2% level), the trader might enter a long position with a stop loss below the 50% level. Use our ROI calculator to evaluate potential trade outcomes.
Example 3: Computer Science -- Algorithm Comparison. Computing F(40) = 102,334,155. The naive recursive approach makes approximately 2^40 (over 1 trillion) function calls and takes several seconds. Memoization reduces this to exactly 40 computations. Matrix exponentiation needs only about 6 matrix multiplications (log2(40) steps). For F(1000), which has 209 digits, the difference between O(2^n) and O(log n) is the difference between "impossible" and "instant."
Tips and Strategies for Working with Fibonacci Numbers
- Use iteration for small n (under 70). For most practical purposes, a simple loop computing F(n) iteratively is the fastest and most reliable approach. Binet's formula introduces floating-point errors beyond about n = 70 without extended precision.
- Apply Zeckendorf representation for unique decomposition. Any positive integer can be written as a sum of non-consecutive Fibonacci numbers. To find the representation, greedily subtract the largest Fibonacci number that fits, then repeat.
- Check Fibonacci membership with the 5n^2 test. A positive integer n is a Fibonacci number if and only if 5n^2 + 4 or 5n^2 - 4 is a perfect square. This test avoids generating the entire sequence.
- Use the GCD identity for number theory problems. The property gcd(F(m), F(n)) = F(gcd(m, n)) is powerful for proofs and computations involving divisibility of Fibonacci numbers.
- Combine Fibonacci retracement with other indicators in trading. Fibonacci levels work best as confluence zones when they align with moving averages, trendlines, or volume profiles rather than being used in isolation.
Fibonacci Numbers in Nature, Art, and Design
Fibonacci numbers appear throughout the natural world due to phyllotaxis. Pinecones show 8 and 13 spirals, pineapples show 8, 13, and 21, and flower petals frequently come in Fibonacci counts: lilies (3), buttercups (5), delphiniums (8), marigolds (13), asters (21), and daisies (34, 55, or 89). DNA molecules measure 34 angstroms long and 21 angstroms wide per full cycle of the double helix. The golden ratio derived from Fibonacci has been used in art and architecture for centuries, from the Parthenon's proportions to Leonardo da Vinci's compositions. The Fibonacci spiral -- quarter-circle arcs through squares with successive Fibonacci side lengths -- approximates the logarithmic spiral found in nautilus shells, hurricanes, and spiral galaxies.
Frequently Asked Questions
What is the Fibonacci sequence and how does it work?
The Fibonacci sequence is a series of numbers where each number equals the sum of the two preceding ones, starting with 0 and 1. The sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on infinitely. The recursive formula is F(n) = F(n-1) + F(n-2). Named after Italian mathematician Leonardo of Pisa (Fibonacci), who introduced it to Western mathematics in his 1202 book Liber Abaci, though it was known to Indian mathematicians centuries earlier.
What is the golden ratio and how does it relate to Fibonacci numbers?
The golden ratio (phi) is approximately 1.6180339887, defined as (1 + sqrt(5))/2. As Fibonacci numbers increase, the ratio of consecutive terms F(n+1)/F(n) converges to phi. By F(20)/F(19), the ratio agrees with phi to four decimal places. This connection means Fibonacci numbers can be calculated directly using Binet's formula: F(n) = (phi^n - psi^n) / sqrt(5), where psi = (1 - sqrt(5))/2.
Where do Fibonacci numbers appear in nature?
Fibonacci numbers appear in the spiral arrangement of sunflower seeds (often 34 and 55 spirals), the branching patterns of trees, the arrangement of leaves around stems (phyllotaxis), the number of petals on many flowers (3, 5, 8, 13, 21), and the spiral patterns of pinecones and pineapples. This occurs because plants grow at angles related to the golden ratio (137.5 degrees), maximizing each leaf's exposure to sunlight.
What are Fibonacci retracement levels in financial trading?
Fibonacci retracement levels are horizontal lines on a price chart at 23.6%, 38.2%, 50%, 61.8%, and 78.6%, derived from dividing Fibonacci numbers by numbers further along the sequence. Traders use these levels to identify potential support and resistance zones where price reversals may occur during a pullback within a trend. The 61.8% level (1/phi) is considered the most significant. Use our ROI calculator to evaluate potential trade outcomes.
Is there a formula to find the nth Fibonacci number directly?
Yes, Binet's formula gives F(n) = (phi^n - (-1/phi)^n) / sqrt(5), where phi = (1 + sqrt(5))/2. For large n, the second term becomes negligible, so F(n) is approximately phi^n / sqrt(5) rounded to the nearest integer. This formula introduces floating-point errors beyond n = 70, so for exact large Fibonacci numbers, the matrix exponentiation method is preferred.
How are Fibonacci numbers used in computer science?
Fibonacci numbers appear throughout computer science. Fibonacci heaps provide optimal amortized time complexity for Dijkstra's and Prim's algorithms. Fibonacci search divides sorted arrays using Fibonacci numbers, requiring only addition and subtraction. Computing the sequence itself is a classic teaching example: naive recursion runs in O(2^n), memoization in O(n), and matrix exponentiation in O(log n), illustrating fundamental algorithm design principles.