# The Fibonacci sequence: from rabbits to the golden ratio, and why slow code loves it

> Add the last two numbers to get the next: 0, 1, 1, 2, 3, 5, 8, 13. That one rule hides a growth pattern, a famous ratio of about 1.618, a stair-climbing puzzle and the classic example of slow recursive code. This guide walks through all four with pictures and exact numbers.

Published 2026-10-08 by Toolcloak. 5 minute read. Original: https://toolcloak.pages.dev/articles/the-fibonacci-sequence-from-rabbits-to-the-golden-ratio-and-why-slow-code-loves-it
Related free tool: [Fibonacci Sequence Generator](https://toolcloak.pages.dev/tools/fibonacci-generator)

In 1202, Leonardo of Pisa, known as Fibonacci, posed a puzzle about rabbits: start with one pair, let every pair that is at least a month old produce a new pair each month, and count the pairs. The answer was a sequence that mathematicians, biologists, traders and programmers still talk about. The rule is so simple that a child can follow it, and the consequences are surprisingly deep.

> **In short**
> - Each term is the **sum of the two before it**: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…
> - The ratio of neighbouring terms settles at the **golden ratio, about 1.618**. Growth is exponential, roughly ×1.618 per step.
> - Climbing **n stairs** taking 1 or 2 steps at a time can be done in **F(n+1)** ways: 10 stairs give 89 routes.
> - Computing it with naive recursion is a classic trap: **F(30) needs 2.7 million calls**; a simple loop needs 30 steps.

## The rule and the first terms

Start with 0 and 1. Every next number is the sum of the previous two: 0 + 1 = 1, 1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, and so on. Some books start at 1, 1 instead of 0, 1. The numbers after the start are identical.

| n | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| F(n) | 0 | 1 | 1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 | 89 | 144 |

*F(n) is the n-th term. F(10) = 55 and F(12) = 144.*

**How each new term is made**

1. **Take the last two.** For example 21 and 34.
2. **Add them.** 21 + 34 = 55.
3. **Slide along.** Now the last two are 34 and 55. Repeat.

Try it: [Fibonacci Sequence Generator](https://toolcloak.pages.dev/tools/fibonacci-generator). Choose how many terms you want and list them, or jump straight to the n-th number.

## The rabbit puzzle

Fibonacci’s puzzle assumes immortal rabbits that mate perfectly, so it is a model rather than zoology. Month 1: one pair, too young to breed. Month 2: still one pair, now mature. Month 3: the pair has a new pair, so two. Month 4: the old pair breeds again, the newer pair is maturing, so three. The pairs per month go 1, 1, 2, 3, 5, 8: exactly the sequence.

**Pairs of rabbits at the start of each month**

|  | Pairs |
| --- | --- |
| Month 1 | 1 |
| Month 2 | 1 |
| Month 3 | 2 |
| Month 4 | 3 |
| Month 5 | 5 |
| Month 6 | 8 |
| Month 7 | 13 |
| Month 8 | 21 |

*Each month the population equals last month’s pairs (who survive) plus the pairs born to everyone who was already mature two months ago.*

## It grows faster than it looks

The early terms are gentle, which hides how quickly the sequence takes off. Roughly every step multiplies the value by 1.618, so it is exponential growth, and the terms soon become huge.

**Some larger terms**

|  | Value | Note |
| --- | --- | --- |
| F(20) | 6,765 | Still small enough to read at a glance |
| F(30) | 832,040 | Over eight lakh |
| F(50) | 12,586,269,025 | More than 12 billion |

*F(90) is already 2,880,067,194,370,816,120, about 2.9 × 10¹⁸.*

**The first 16 terms (values)**

| Term number 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 |
| 13 | 233 |
| 14 | 377 |
| 15 | 610 |

*The curve is flat for the first few terms and then bends steeply upward, the signature of exponential growth.*

If that shape looks familiar, it is the same curve you meet in [compound growth](https://toolcloak.pages.dev/articles/start-at-25-or-35-what-waiting-ten-years-really-costs) and the [rule of 72](https://toolcloak.pages.dev/articles/the-rule-of-72-how-long-money-takes-to-double). Fibonacci growth is like earning about 61.8% per step, with the nice twist that the “interest” comes from the sequence’s own past.

## The golden ratio appears

Divide each term by the one before it and watch what happens. The first ratios jump around (1, 2, 1.5, 1.67), then quickly calm down and approach **1.6180339…**, known as the **golden ratio** and written with the Greek letter phi (φ).

**Ratio of each term to the one before it: F(n+1) ÷ F(n)**

| n | F(n+1) ÷ F(n) | Golden ratio φ |
| --- | --- | --- |
| 1 | 1 | 1.618 |
| 2 | 2 | 1.618 |
| 3 | 1.5 | 1.618 |
| 4 | 1.6667 | 1.618 |
| 5 | 1.6 | 1.618 |
| 6 | 1.625 | 1.618 |
| 7 | 1.6154 | 1.618 |
| 8 | 1.619 | 1.618 |
| 9 | 1.6176 | 1.618 |
| 10 | 1.6182 | 1.618 |
| 11 | 1.618 | 1.618 |
| 12 | 1.6181 | 1.618 |

*The blue line oscillates around the amber line, getting closer each time. By n = 10 the ratio is correct to three decimals.*

> **φ = (1 + √5) ÷ 2 ≈ 1.6180339887:** It is the positive solution of x² = x + 1. That equation is the Fibonacci rule in disguise: ‘this term squared’ equals ‘this term plus one’ in ratio form, which is why the ratios of neighbours must settle on it.

Because of this, there is even a direct formula, Binet’s formula: F(n) = (φⁿ − (1 − φ)ⁿ) ÷ √5. Since (1 − φ) is about −0.618, its powers shrink to nothing, so F(n) is simply φⁿ ÷ √5 rounded to the nearest whole number. For n = 10: 1.618¹⁰ ÷ 2.236 ≈ 55.0.

> **Be careful with the nature claims:** Sunflower seed spirals and pinecone scales often have counts such as 34 and 55, or 21 and 34, which are Fibonacci numbers. That is a real pattern in many plants, not a law, and not every flower follows it. Many “golden ratio in art and the human face” claims are loose or untrue. Enjoy the real examples without stretching them.

## Climbing stairs and counting ways

Here is a puzzle that has nothing to do with rabbits. You can climb a staircase by taking either 1 or 2 steps at a time. How many different routes are there for n steps? The last move was either a single step (leaving n − 1 steps before it) or a double step (leaving n − 2). So ways(n) = ways(n − 1) + ways(n − 2): the Fibonacci rule again.

**Number of ways to climb n stairs with steps of 1 or 2**

|  | Routes |
| --- | --- |
| 5 stairs | 8 |
| 10 stairs | 89 |
| 15 stairs | 987 |
| 20 stairs | 10946 |

*The count for n stairs is F(n + 1). Twenty stairs already have 10,946 different routes.*

Another identity: the sum of the first n terms (from F(1)) is F(n + 2) − 1. Check with the first ten: 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 + 55 = 143, and F(12) − 1 = 144 − 1 = 143.

## Why programmers use it as a warning

Fibonacci is the standard example of recursion, a function that calls itself: fib(n) = fib(n − 1) + fib(n − 2). It is elegant, and it is slow, because the same values are recomputed again and again. fib(5) calls fib(4) and fib(3), and fib(4) calls fib(3) again, and so on.

**Two ways to compute F(30)**

| Naive recursion | A simple loop (or memoisation) |
| --- | --- |
| 2,692,537 calls | 30 steps |
| Recomputes the same terms repeatedly | Keeps only the last two values |
| Time roughly doubles with every extra step | Time grows in a straight line with n |
| F(40) needs about 331 million calls | Easily handles F(10,000) with big integers |

*The number of calls for naive recursion is 2 × F(n + 1) − 1, so the slowness is itself a Fibonacci sequence.*

**The fast way, step by step (for F(6))**

1. **Start.** a = 0, b = 1.
2. **Repeat 6 times.** Replace (a, b) with (b, a + b): (1,1), (1,2), (2,3), (3,5), (5,8), (8,13).
3. **Read the answer.** After 6 rounds, a = 8, which is F(6).

> **Watch your number types:** In JavaScript, ordinary numbers are exact only up to 9,007,199,254,740,991. F(78) = 8,944,394,323,791,464 still fits but F(79) = 14,472,334,024,676,221 does not, and results after that start to be wrong in the last digits. Use BigInt, or a big-integer type, for large terms. The same limit is why [Unix time](https://toolcloak.pages.dev/articles/unix-time-the-number-that-counts-seconds-since-1970) and IDs sometimes need 64 bits.

## Quick practice

1. What comes after 55, 89? **144** (55 + 89).
2. How many ways to climb 6 stairs with steps of 1 or 2? F(7) = **13**.
3. Estimate F(12) with φⁿ ÷ √5: 1.618¹² ≈ 321.99, divided by 2.236 gives 144.0. Rounded: **144**.
4. Is 1,000,000 a Fibonacci term? No. The terms near it are 832,040 (F(30)) and 1,346,269 (F(31)).

A rule you can say in one breath turns out to describe breeding rabbits, climbing stairs and a ratio that appears all over geometry, while also teaching every new programmer why smart algorithms matter. Try the generator above to see 50 terms in a flash, and notice how fast the numbers grow after the first few. For another kind of number pattern, read about [prime numbers](https://toolcloak.pages.dev/articles/prime-numbers-why-they-thin-out-and-why-your-bank-depends-on-them).

## Frequently asked questions

### What is the Fibonacci sequence?

A sequence in which each number is the sum of the two before it, starting 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.

### What is the golden ratio?

About 1.6180339887, the value that the ratio of consecutive Fibonacci numbers approaches. It equals (1 + √5) ÷ 2.

### What is the 10th Fibonacci number?

55, if you count F(0) = 0, F(1) = 1. Counting from F(1) = 1, F(2) = 1, the tenth term is also 55.

### Is there a formula for the n-th Fibonacci number?

Yes, Binet’s formula: F(n) = (φⁿ − (1 − φ)ⁿ) ÷ √5. In practice F(n) is φⁿ ÷ √5 rounded to the nearest integer.

### Why is recursive Fibonacci slow?

It recomputes the same values many times, so the number of calls grows exponentially. F(30) takes about 2.7 million calls, while a loop needs 30 steps.

### Do all flowers follow Fibonacci numbers?

No. Many sunflowers, pinecones and pineapples show Fibonacci counts in their spirals, but it is a common pattern, not a rule.

