Fibonacci Sequence Generator & Calculator
Generate Fibonacci sequences up to 1,000+ terms or calculate any Nth term instantly. Get exact BigInt results, custom output formats, and Fibonacci number lookup.
Fibonacci Sequence Generator & Calculator
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181
| Index (n) | Ratio Equation | Calculated Ratio (F_n / F_n-1) | Difference from Phi (φ) |
|---|---|---|---|
| n = 2 | 1 / 1 | 1.0000000000 | 6.1803e-1 |
| n = 3 | 2 / 1 | 2.0000000000 | 3.8197e-1 |
| n = 4 | 3 / 2 | 1.5000000000 | 1.1803e-1 |
| n = 5 | 5 / 3 | 1.6666666667 | 4.8633e-2 |
| n = 6 | 8 / 5 | 1.6000000000 | 1.8034e-2 |
| n = 7 | 13 / 8 | 1.6250000000 | 6.9660e-3 |
| n = 8 | 21 / 13 | 1.6153846154 | 2.6494e-3 |
| n = 9 | 34 / 21 | 1.6190476190 | 1.0136e-3 |
| n = 10 | 55 / 34 | 1.6176470588 | 3.8693e-4 |
| n = 11 | 89 / 55 | 1.6181818182 | 1.4783e-4 |
| Step | Recurrence Addition Equation | Resulting Term Value |
|---|---|---|
| F(2) | F(2) = 1 + 0 = 1 | 1 |
| F(3) | F(3) = 1 + 1 = 2 | 2 |
| F(4) | F(4) = 2 + 1 = 3 | 3 |
| F(5) | F(5) = 3 + 2 = 5 | 5 |
| F(6) | F(6) = 5 + 3 = 8 | 8 |
| F(7) | F(7) = 8 + 5 = 13 | 13 |
| F(8) | F(8) = 13 + 8 = 21 | 21 |
| F(9) | F(9) = 21 + 13 = 34 | 34 |
| F(10) | F(10) = 34 + 21 = 55 | 55 |
| F(11) | F(11) = 55 + 34 = 89 | 89 |
| F(12) | F(12) = 89 + 55 = 144 | 144 |
| F(13) | F(13) = 144 + 89 = 233 | 233 |
| F(14) | F(14) = 233 + 144 = 377 | 377 |
| F(15) | F(15) = 377 + 233 = 610 | 610 |
| F(16) | F(16) = 610 + 377 = 987 | 987 |
| F(17) | F(17) = 987 + 610 = 1597 | 1597 |
| F(18) | F(18) = 1597 + 987 = 2584 | 2584 |
| F(19) | F(19) = 2584 + 1597 = 4181 | 4181 |
Overview: How to Generate a Fibonacci Sequence
The Fibonacci sequence is one of the most famous mathematical patterns in number theory, computer science, and nature. It begins with 0 and 1, and each subsequent term is calculated by adding the two preceding terms:
The ToolMono Fibonacci Sequence Generator & Calculator satisfies three distinct user intents in one interface: generating sequential series, calculating exact Nth terms (e.g. F(100)), and checking Fibonacci membership for any input integer. Explore companion math tools: Prime Number Checker, GCD & LCM Calculator, Online Calculator, Scientific Calculator, Binary ↔ Decimal Converter, Decimal ↔ Hex Converter, and Decimal ↔ Octal Converter.
How to Use the Generator & Calculator
Select First N Terms to generate an ordered list up to 2,000 BigInt terms with custom output formatting (Comma, JSON, CSV, Markdown).
Select Nth Term Calculator to compute any single Fibonacci term F(n) instantly with 100% BigInt integer precision.
Select Fibonacci Membership Checker to test if a number (e.g. 144) is Fibonacci via exact 5x² ± 4 perfect square tests.
Toggle between standard zero-indexed F(0)=0, F(1)=1 and legacy F(1)=1, F(2)=1 conventions.
Fibonacci Sequence Formula and Recurrence Relation
The Fibonacci sequence is defined mathematically by the linear recurrence relation:
with initial seed conditions:
How to Calculate the Nth Fibonacci Number
There are several computational methods to calculate the $n$-th Fibonacci term:
| Method | Time Complexity | Space Complexity | Precision & Memory Characteristics |
|---|---|---|---|
| Fast Doubling | O(log N) | O(log N) | Fastest exact BigInt method for large indices |
| Iterative Loop | O(N) | O(1) | Ideal for generating full sequential output arrays |
| Matrix Exponentiation | O(log N) | O(1) | Uses matrix powers [[1,1],[1,0]]^n |
| Binet's Formula | O(1) | O(1) | Closed-form floating point (loses precision beyond n > 70) |
Binet's Formula and Exact Fibonacci Calculations
Binet's formula provides a closed-form expression for calculating $F(n)$ directly using the Golden Ratio:
where:
While Binet's formula is mathematically exact in real numbers, computing it using 64-bit floating-point numbers causes rounding errors for $n > 70$. ToolMono uses native JavaScript BigInt arithmetic for $100\%$ exact integer output up to thousands of digits.
Fibonacci Numbers and the Golden Ratio (Phi φ)
The ratio of consecutive Fibonacci numbers approaches the Golden Ratio $\phi$ as the index increases:
| Index (n) | Ratio Equation | Calculated Ratio | Difference from φ |
|---|---|---|---|
| n = 2 | 1 / 1 | 1.0000000000 | 0.6180 |
| n = 5 | 5 / 3 | 1.6666666667 | 0.0486 |
| n = 10 | 55 / 34 | 1.6176470588 | 0.00038 |
| n = 20 | 6765 / 4181 | 1.6180339887 | 0.000000002 |
Sum of Fibonacci Terms
The sum of the first $n$ Fibonacci terms satisfies the elegant identity:
Fibonacci Quick Reference Table
Exact values for key Fibonacci terms verified against BigInt calculations:
| Index (n) | F(n) Exact Value | Digit Length |
|---|---|---|
| n = 0 | 0 | 1 digits |
| n = 1 | 1 | 1 digits |
| n = 2 | 1 | 1 digits |
| n = 3 | 2 | 1 digits |
| n = 4 | 3 | 1 digits |
| n = 5 | 5 | 1 digits |
| n = 10 | 55 | 2 digits |
| n = 20 | 6765 | 4 digits |
| n = 30 | 832040 | 6 digits |
| n = 50 | 12586269025 | 11 digits |
| n = 78 | 8944394323791464 | 16 digits |
| n = 79 | 14472334024676221 | 17 digits |
| n = 100 | 354224848179261915075 | 21 digits |
Fibonacci Indexing: F(0) vs F(1)
Two primary indexing conventions exist in literature and software:
F(0) = 0, F(1) = 1, F(2) = 1, F(3) = 2. Used in computer science and modern university mathematics.
F(1) = 1, F(2) = 1, F(3) = 2, F(4) = 3. Used in some school textbooks and classical number theory texts.
Fibonacci Number Edge Cases & Membership
- Is 0 a Fibonacci number? Yes, under standard zero-indexing F(0) = 0.
- Is 1 a Fibonacci number? Yes, it appears twice as F(1) = 1 and F(2) = 1.
- Negative Fibonacci Indices (Negafibonacci): Extends Fibonacci to negative indices via F(-n) = (-1)^(n+1) × F(n). E.g. F(-1) = 1, F(-2) = -1, F(-3) = 2.
Fibonacci Membership Algorithm (5x² ± 4 Test)
To test whether an integer $x$ is a Fibonacci number without generating the sequence, use Gessel's Theorem:
Example for x = 144:
Production Code Implementations
export function fibonacciSequence(n) {
if (n <= 0) return [];
const seq = [0n];
if (n === 1) return seq;
seq.push(1n);
for (let i = 2; i < n; i++) {
seq.push(seq[i - 1] + seq[i - 2]);
}
return seq;
}export function fastDoublingBigInt(n) {
if (n === 0n) return [0n, 1n];
const [a, b] = fastDoublingBigInt(n >> 1n);
const c = a * (2n * b - a);
const d = a * a + b * b;
return (n & 1n) === 0n ? [c, d] : [d, c + d];
}def fibonacci_sequence(n: int) -> list[int]:
if n <= 0:
return []
seq = [0, 1]
for i in range(2, n):
seq.append(seq[-1] + seq[-2])
return seq[:n]def fast_doubling(n: int) -> tuple[int, int]:
if n == 0:
return (0, 1)
a, b = fast_doubling(n >> 1)
c = a * (2 * b - a)
d = a * a + b * b
if n & 1:
return (d, c + d)
else:
return (c, d)public static BigInteger[] fibonacci(int n) {
BigInteger[] seq = new BigInteger[n];
if (n > 0) seq[0] = BigInteger.ZERO;
if (n > 1) seq[1] = BigInteger.ONE;
for (int i = 2; i < n; i++) {
seq[i] = seq[i - 1].add(seq[i - 2]);
}
return seq;
}// Fast Doubling O(log N) BigInteger
public static BigInteger getNthFibonacci(int n) {
return fastDoubling(n)[0];
}package main
import "math/big"
func Fibonacci(n int) []*big.Int {
seq := make([]*big.Int, n)
if n > 0 { seq[0] = big.NewInt(0) }
if n > 1 { seq[1] = big.NewInt(1) }
for i := 2; i < n; i++ {
seq[i] = new(big.Int).Add(seq[i-1], seq[i-2])
}
return seq
}// Go Fast Doubling O(log N) BigInt
#include <vector>
#include <iostream>
std::vector<long long> fibonacci(int n) {
if (n <= 0) return {};
std::vector<long long> seq = {0, 1};
for (int i = 2; i < n; i++) {
seq.push_back(seq[i - 1] + seq[i - 2]);
}
return seq;
}// C++ Fast Doubling / Matrix Exponentiation
fn fibonacci(n: usize) -> Vec<u128> {
if n == 0 { return vec![]; }
let mut seq = vec![0, 1];
for i in 2..n {
let next = seq[i - 1] + seq[i - 2];
seq.push(next);
}
seq.truncate(n);
seq
}fn fast_doubling(n: u64) -> (u128, u128) {
if n == 0 { return (0, 1); }
let (a, b) = fast_doubling(n >> 1);
let c = a * (2 * b - a);
let d = a * a + b * b;
if n & 1 == 1 { (d, c + d) } else { (c, d) }
}Common Mathematical & Coding Errors
- Using Standard Floats for Large N: JavaScript
Numberloses integer precision for F(n) when n > 78. Always useBigInt. - Naive Recursion Overhead: Computing F(n) recursively without memoization runs in exponential time $O(2^N)$, causing stack overflow for $n > 40$.
- Confusing Term Count with Maximum Index: Generating "10 terms" produces F(0) through F(9), whereas generating "through index 10" produces 11 terms.
Performance & Complexity Analysis
- Time Complexity: Fast Doubling operates in $O(\log N)$ bitwise operations.
- Space Complexity: $O(1)$ auxiliary space for single-term calculation.
- Browser Safety: Client-side BigInt execution prevents browser UI freezes.
Best Practices
Always use BigInt in JavaScript for $n \ge 78$ to prevent numeric precision loss.
Use $O(\log N)$ Fast Doubling when fetching isolated $N$-th terms without needing previous terms.
Frequently Asked Questions
References & Standards
NIST Digital Library of Mathematical Functions
NIST reference for Fibonacci sequences and Binet's formula.
ISO 80000-2: Mathematics Notation Standard
ISO standard for mathematical sequences and recurrence relations.
ECMAScript BigInt Specification
Official specification for arbitrary-precision integer calculations.
Related Tools
Browse all toolsPrime Number Checker
Check if a number is prime or composite instantly. Get factors, prime factorization, trial-division details, and neighboring prime numbers with this free online prime checker.
GCD and LCM Calculator
Calculate the GCD (GCF/HCF) and LCM of two or more numbers instantly. See step-by-step Euclidean algorithm and prime factorization methods with accurate results.
Online Calculator
Use ToolMono's free online calculator for quick everyday math, expressions, percentages, powers, roots, and parentheses. Includes calculation history and keyboard support.
Scientific Calculator
Use ToolMono's free Scientific Calculator for advanced mathematical calculations. Supports trigonometric, inverse, hyperbolic, logarithmic, exponential, factorial, scientific notation, degree/radian modes, calculation history, and 100% client-side processing.
Percentage Calculator
Calculate percentages instantly with ToolMono's free online percentage calculator. Find X% of Y, calculate what percent X is of Y, and solve reverse percentages.
Binary ↔ Decimal Converter
Free online Binary Decimal Converter. Convert binary base-2 to decimal base-10 instantly. Supports BigInt, two's complement, 8–256 bit signed, and step breakdown.
Decimal ↔ Hex Converter
Free online Decimal to Hex Converter. Convert base-10 to base-16 hexadecimal instantly. Supports BigInt, two's complement, 8–64 bit signed/unsigned, and live steps.
Decimal to Octal Converter
Free online Decimal to Octal converter with instant step-by-step division steps. Convert Base-10 to Base-8 and Octal to Decimal accurately in your browser.