Fibonacci Sequence Generator
Generate Fibonacci numbers up to any length.
Reviewed by Aygul Dovletova · Last reviewed
Using the Fibonacci Generator
- Enter a count - how many Fibonacci numbers you want, from 1 up to 100. The input accepts integer keystrokes only.
- Press Generate. The sequence renders instantly and each number is laid out in a monospace grid so long values stay aligned.
- Check the running sum below the list; it equals F(n+2) - 1 by a classic identity, and the tool computes it as it iterates.
- Copy the sequence with the Copy All button. The result is a comma-separated string, ready to drop into a spreadsheet or a code editor.
- Clear and try a new count as often as you like; nothing is cached between runs.
How the Sequence Is Computed
The tool uses bottom-up iterative accumulation: it starts with a = 0n and b = 1n, then repeatedly assigns [a, b] = [b, a + b] until it has produced the requested count. Addition uses JavaScript BigInt because the 80th Fibonacci number already exceeds 253-1, the limit of safe integers in Number, and F(100) is a 21-digit integer. Without BigInt the higher terms would silently round.
Alternative computation paths exist. The closed-form Binet's formula F(n) = (φn - ψn) / √5, where φ = (1 + √5) / 2 is the golden ratio and ψ = (1 - √5) / 2, gives the nth term in constant time but only matches the true integer up to around F(70) before IEEE 754 floating-point error dominates. Matrix exponentiation of [[1, 1], [1, 0]]n gives F(n) in O(log n) multiplications, the right choice if you only want one very distant term. For a sequential list up to n = 100, the iterative loop wins on simplicity.
Why You Might Reach For Fibonacci
- Mocking up Fibonacci retracement levels for a charting demo without a trading platform.
- Producing a sequence to feed into a golden-ratio layout grid for a design mockup.
- Writing a programming-contest solution that needs exact large Fibonacci values without installing a big-integer library.
- Seeding a test fixture for a memoisation or dynamic-programming lesson.
- Demonstrating the convergence of F(n+1)/F(n) to φ for a math club.
- Generating sizes for a Fibonacci-spaced UI tile layout or a natural-looking progression of delays.
Edge Cases Worth Knowing
- Where does the sequence start? Modern convention says F(0) = 0, F(1) = 1, matching OEIS sequence A000045 and every standard reference. The tool uses this convention, so requesting 1 number gives
[0]and requesting 2 gives[0, 1]. - Counts above 100 are blocked at the UI layer. F(100) is 354,224,848,179,261,915,075; higher terms scale roughly by factor 1.618 per step and would quickly overwhelm the output pane.
- Very large values stay exact thanks to BigInt. F(100) displays in full, no scientific notation, no rounding.
- Sum precision is also BigInt, so the sum of the first 100 Fibonacci numbers is 927,372,692,193,078,999,175 exactly, not rounded.
- Zero count is treated as empty - the output pane shows nothing rather than throwing an error.
- The displayed ratio between consecutive terms stabilises at the golden ratio φ ≈ 1.6180339887 by about F(20); the decimal is truncated to 10 places on display.
A Short History of the Sequence
The sequence appears in Indian prosody a thousand years before Fibonacci, first described by Pingala around 450 BCE and elaborated by Virahanka (sixth century CE), Gopala, and Hemachandra (twelfth century) for counting Sanskrit metres. It reached Europe through Leonardo of Pisa, known as Fibonacci, who used it in the Liber Abaci (1202) to model an idealised rabbit-breeding problem: starting with one pair, each mature pair produces a new pair every month. The golden ratio connection was known to the Greeks (Euclid's extreme and mean ratio) but the algebraic link with the sequence - the ratio F(n+1)/F(n) → φ - was formalised by Kepler in 1611. Binet's closed form was published by Jacques Philippe Marie Binet in 1843, although de Moivre and Euler had both derived it earlier. ISO standard notation uses Fn for the nth term.
Browser Tool vs. Code Libraries and OEIS
If you need a single very large term, sympy.fibonacci in Python or Fibonacci in Mathematica will give you F(106) in under a second using fast doubling. The OEIS (oeis.org) maintains the definitive sequence database, with B-files containing the first 104 or more terms pre-computed. Hardware calculators usually top out at around F(50) because of their display precision. Spreadsheets can compute up to about F(70) before losing integer precision in the default double-precision format. What this browser tool gives you is a no-install, exact-arithmetic list of any prefix up to 100, with the sum identity demonstrated visually - ideal for quick reference, classroom use, and checking other tools.
Frequently Asked Questions
Why does the sequence start with 0 rather than 1?
The modern convention pins <em>F</em>(0) = 0 and <em>F</em>(1) = 1. This is the convention used by OEIS A000045, Knuth's <em>The Art of Computer Programming</em>, and most contemporary combinatorics textbooks. Starting from 0 makes the recurrence <em>F</em>(<em>n</em>) = <em>F</em>(<em>n</em>-1) + <em>F</em>(<em>n</em>-2) work for all <em>n</em> ≥ 2 without a special case, and it lines up with the indexing used in Binet's formula.
How does Binet's formula relate to what the tool computes?
Binet's formula <em>F</em>(<em>n</em>) = (φ<sup><em>n</em></sup> - ψ<sup><em>n</em></sup>) / √5 gives the <em>n</em>th Fibonacci number in closed form, where φ is the golden ratio and ψ = 1 - φ. The tool does not use it directly because IEEE 754 doubles only have 53 bits of mantissa and φ<sup><em>n</em></sup> loses integer precision by about <em>n</em> = 70. Iterative integer accumulation with BigInt gives exact answers for every <em>n</em> ≤ 100.
Why is BigInt needed for larger terms?
JavaScript's default <code>number</code> type stores integers exactly only up to 2<sup>53</sup>-1. <em>F</em>(78) is already 8,944,394,323,791,464 and <em>F</em>(79) is 14,472,334,024,676,221, both comfortably in range; <em>F</em>(80) is 23,416,728,348,467,685, which also fits. Above that, 64-bit floats round to the nearest representable integer, so <em>F</em>(80) through <em>F</em>(100) would silently be off by a few units. BigInt, added to the language in ES2020, stores arbitrary-precision integers and eliminates the problem.
Does the server see my count or the output?
No. The Preact component computes the sequence entirely in your tab using BigInt arithmetic, and the Copy All button writes to the local clipboard. There is no POST request for the count, no logging of the generated numbers, and nothing is stored after you leave the page. A DevTools Network trace confirms zero outbound requests during generation.
What is the relationship to the golden ratio?
The ratio of consecutive Fibonacci numbers converges to the golden ratio φ = (1 + √5) / 2 ≈ 1.6180339887. By the time you reach <em>F</em>(20)/<em>F</em>(19), the ratio agrees with φ to eight decimal places. This is a direct consequence of Binet's closed form: as <em>n</em> grows, the ψ<sup><em>n</em></sup> term shrinks to zero because |ψ| < 1, leaving φ<sup><em>n</em></sup>/√5 as the dominant part.
Is there a pattern in the last digits of Fibonacci numbers?
Yes, and a beautiful one. The sequence of last decimal digits repeats with period 60 (the Pisano period for modulus 10). More generally, the Pisano period for any modulus <em>m</em> is the length of the cycle of <em>F</em>(<em>n</em>) mod <em>m</em>. For large <em>m</em> the period divides 6<em>m</em>. This is why modular Fibonacci computations never require arbitrary precision - you only need to iterate up to the period length.
Why cap at 100 instead of 1000?
<em>F</em>(100) is already 21 digits; <em>F</em>(1000) is 209 digits, which would be unreadable in a grid layout. BigInt computation remains fast up to at least <em>F</em>(10,000), but the UI would need pagination, chunked rendering, and probably a download link. For very distant terms use a language REPL with fast doubling or the OEIS B-files.
What does the sum of the first <em>n</em> Fibonacci numbers equal?
A classic identity: the sum of <em>F</em>(0) through <em>F</em>(<em>n</em>) equals <em>F</em>(<em>n</em>+2) - 1. You can verify it from the sequence itself: 0 + 1 + 1 + 2 + 3 + 5 = 12 = <em>F</em>(8) - 1 = 13 - 1. The proof is a two-line telescoping argument. The tool uses this identity to cross-check its accumulated sum in development, although the displayed sum is the plain running total.
Can Fibonacci numbers be negative?
Yes, if you extend the sequence backwards. <em>F</em>(-<em>n</em>) = (-1)<sup><em>n</em>+1</sup> <em>F</em>(<em>n</em>), giving 0, 1, -1, 2, -3, 5, -8, 13, ... as you step into negative indices. The tool does not expose negative indices because the usual practical need is for the forward sequence. If you need them, compute <em>F</em>(<em>n</em>) for the positive index and apply the sign rule.
How does iteration compare to matrix exponentiation?
Iteration is <em>O</em>(<em>n</em>) operations; matrix exponentiation of [[1,1],[1,0]]<sup><em>n</em></sup> by repeated squaring is <em>O</em>(log <em>n</em>). For a sequential list up to <em>n</em>, iteration wins because it reuses work; for a single distant term, matrix power or fast doubling wins.
More Math & Calculators
Age Calculator
Calculate exact age in years, months and days from a birthdate.
Open toolArea & Volume Calculator
Calculate area of 2D shapes and volume of 3D solids.
Open toolBMI Calculator
Calculate your Body Mass Index and find your weight category.
Open toolByte / Bit Converter
Convert between bits, bytes, KB, MB, GB, TB and PB.
Open toolDiscount Calculator
Calculate discount amount, sale price, savings, and discounted value with optional sales tax. Supports stacked coupons.
Open toolFraction Calculator
Add, subtract, multiply and divide fractions with simplified results.
Open tool