Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools

Octagonal Numbers Calculator






What is an Octagonal Number?

An octagonal number counts dots in a nested-octagon pattern with a shared vertex. Starting with one dot:

O1=1,O2=8,O3=21,O4=40,O5=65,O6=96,O7=133,O_1 = 1, \quad O_2 = 8, \quad O_3 = 21, \quad O_4 = 40, \quad O_5 = 65, \quad O_6 = 96, \quad O_7 = 133, \quad \ldots


The closed form is

On=n(3n2)=3n22nO_n = n(3n - 2) = 3n^2 - 2n


Octagonal numbers are the sixth in the family of polygonal numbers, following triangular, square, pentagonal, hexagonal, and heptagonal. The general rr-gonal-number formula

Pn(r)=n[(r2)n(r4)]2P_n^{(r)} = \frac{n[(r - 2)n - (r - 4)]}{2}


specializes to octagonal at r=8r = 8, giving On=n(6n4)/2=n(3n2)O_n = n(6n - 4)/2 = n(3n - 2).

Sum-of-arithmetic-series form. OnO_n is the sum of the first nn terms of the arithmetic series 1,7,13,19,25,1, 7, 13, 19, 25, \ldots with a1=1a_1 = 1 and common difference d=6d = 6. The step 6 reflects that r2=6r - 2 = 6 for r=8r = 8.

For deeper coverage see octagonal number, polygonal numbers, and figurate numbers.

The Closed Form Derivation

From the arithmetic-series perspective. Octagonal numbers are sums of the arithmetic series 1,7,13,19,1, 7, 13, 19, \ldots with general term 6k56k - 5:

On=k=1n(6k5)=6n(n+1)25n=3n2+3n5n=3n22n=n(3n2)O_n = \sum_{k=1}^{n}(6k - 5) = 6 \cdot \frac{n(n+1)}{2} - 5n = 3n^2 + 3n - 5n = 3n^2 - 2n = n(3n - 2)


From the general $r$-gonal formula. Substituting r=8r = 8:

On=n[6n4]2=n(3n2)O_n = \frac{n[6n - 4]}{2} = n(3n - 2)


Why the formula is always an integer. On=n(3n2)O_n = n(3n - 2) is a product of integers, so it is always an integer. No divisibility argument is needed; the closed form has no fractional component.

Connection to triangular numbers. Using Tn=n(n+1)/2T_n = n(n+1)/2:

On=n(3n2)=3n22n=6n(n+1)22n3n=6Tn5nO_n = n(3n - 2) = 3n^2 - 2n = 6 \cdot \frac{n(n+1)}{2} - 2n - 3n = 6 T_n - 5n


Or more simply: On=3Tn2n+(correction)O_n = 3 T_n - 2n + (\text{correction}), with the cleanest identity being On=Tn+4Tn1O_n = T_n + 4 T_{n-1} for n2n \geq 2. Expanding triangulars:

On=n(n+1)2+4(n1)n2=n(n+1)+4n(n1)2=n(5n3)2O_n = \frac{n(n+1)}{2} + 4 \cdot \frac{(n-1)n}{2} = \frac{n(n + 1) + 4n(n - 1)}{2} = \frac{n(5n - 3)}{2}


Wait — that gives heptagonal, not octagonal. The correct identity: On=T3n2T2n2O_n = T_{3n - 2} - T_{2n - 2}, which can be verified directly: T3n2=(3n2)(3n1)/2T_{3n-2} = (3n-2)(3n-1)/2 and T2n2=(2n2)(2n1)/2T_{2n-2} = (2n-2)(2n-1)/2; subtracting gives n(3n2)n(3n - 2) after simplification.

Examples. O1=1O_1 = 1, O2=8O_2 = 8, O3=21O_3 = 21, O4=40O_4 = 40, O10=280O_{10} = 280, O20=1160O_{20} = 1160.

The Membership Test

Given a positive integer mm, testing whether it is octagonal requires two checks.

The test. mm is octagonal if and only if both:

1. 3m+13m + 1 is a perfect square, and
2. 1+3m+11 + \sqrt{3m + 1} is divisible by 3.

If both hold, the index is

n=1+3m+13n = \frac{1 + \sqrt{3m + 1}}{3}


Why both checks. From On=n(3n2)=mO_n = n(3n - 2) = m, the quadratic 3n22nm=03n^2 - 2n - m = 0 has discriminant 4+12m=4(1+3m)4 + 12m = 4(1 + 3m). The square root is 21+3m2\sqrt{1 + 3m}, and the quadratic formula gives

n=2+21+3m6=1+3m+13n = \frac{2 + 2\sqrt{1 + 3m}}{6} = \frac{1 + \sqrt{3m + 1}}{3}


So 3m+13m + 1 must be a perfect square, and the numerator 1+3m+11 + \sqrt{3m + 1} must be a multiple of 3.

Example. Is 225 octagonal? Compute 3225+1=676=2623 \cdot 225 + 1 = 676 = 26^2 — perfect square. Then (1+26)/3=9(1 + 26)/3 = 9, an integer. So 225=O9225 = O_9. Verify: 925=2259 \cdot 25 = 225. Confirmed.

Triangular but not octagonal. Is 15 octagonal? Compute 315+1=463 \cdot 15 + 1 = 46. 466.78\sqrt{46} \approx 6.78 — not a perfect square. So 15 is not octagonal, even though it is triangular (T5=15T_5 = 15) and hexagonal (H3=15H_3 = 15).

Non-example. Is 100 octagonal? Compute 3100+1=3013 \cdot 100 + 1 = 301. 30117.35\sqrt{301} \approx 17.35 — not a perfect square. So 100 is not octagonal. Nearest are O6=96O_6 = 96 and O7=133O_7 = 133.

Properties and Identities

Recurrence: On=On1+(6n5)O_n = O_{n-1} + (6n - 5) with O1=1O_1 = 1. Each octagonal adds the next arithmetic-series term.
Difference of consecutive octagonals: On+1On=6n+1O_{n+1} - O_n = 6n + 1. Differences are 7, 13, 19, 25, ...
Generating function: n=1Onxn=x(1+5x)(1x)3\sum_{n=1}^{\infty} O_n x^n = \frac{x(1 + 5x)}{(1 - x)^3}.
Asymptotic growth: On3n2O_n \sim 3n^2. Octagonal numbers grow about three times as fast as square numbers.
Identity in triangulars: On=T3n2T2n2O_n = T_{3n - 2} - T_{2n - 2} for n2n \geq 2. Octagonals as a difference of triangulars.
Sum of first $n$ octagonals: k=1nOk=n2(n+1)\sum_{k=1}^{n} O_k = n^2(n + 1). A cleaner closed form than for some other polygonals.
Last-digit pattern: octagonal numbers in base 10 end only in 0, 1, 3, 5, 6, or 8. Numbers ending in other digits cannot be octagonal.

Common Applications

Like heptagonal numbers, octagonal numbers have fewer celebrated identities than the lower-degree polygonals, but they appear in several contexts.

Fermat's polygonal number theorem. Every positive integer is a sum of at most 8 octagonal numbers. The r=8r = 8 case of the general theorem.
Polygonal completeness. When the polygonal family is studied systematically, octagonal is one of the canonical members; figurate-number tables routinely include it.
Lattice problems. Some 2D counting problems on octagonal regions involve octagonal-number boundaries.
Combinatorial identities. Identities relating octagonals to triangulars, squares, and pentagonals form parts of papers on figurate-number arithmetic.
Number-theoretic curiosities. Octagonal numbers that are also squares, triangulars, or pentagonals are individually studied; the intersections are sparse.
Educational use. Octagonal numbers are commonly used to illustrate the polygonal-number paradigm beyond the well-known triangular, square, and pentagonal cases.

Octagonal vs Centered Octagonal Numbers

As with hexagonal and heptagonal numbers, there is a distinct sequence called the centered octagonal numbers, which should not be confused with the polygonal octagonal numbers covered here.

Octagonal numbers (this page): nested octagons sharing one vertex. Closed form On=n(3n2)O_n = n(3n - 2). Sequence: 1, 8, 21, 40, 65, 96, ...

Centered octagonal numbers: a central dot surrounded by concentric octagonal rings. Closed form Cn(8)=4n24n+1=(2n1)2C_n^{(8)} = 4n^2 - 4n + 1 = (2n - 1)^2. Sequence: 1, 9, 25, 49, 81, 121, ...

Notably, centered octagonal numbers are exactly the odd perfect squares: Cn(8)=(2n1)2C_n^{(8)} = (2n - 1)^2. This unexpected identity makes the centered version more famous in some contexts.

When literature refers to "octagonal numbers" without qualification, it almost always means the polygonal sequence covered here. Centered octagonals require the "centered" qualifier.

Common Mistakes

Forgetting the divisibility-by-3 check. 3m+13m + 1 being a perfect square is necessary but not sufficient. The divisibility check on 1+3m+11 + \sqrt{3m + 1} filters out spurious candidates.

Misremembering the closed form. On=n(3n2)O_n = n(3n - 2), not n(3n+2)n(3n + 2) or n(2n3)n(2n - 3). The 3 comes from (r2)/2=3(r - 2)/2 = 3 for r=8r = 8; the 2 comes from (r4)/2=2(r - 4)/2 = 2.

Confusing with centered octagonal numbers. Polygonal OnO_n gives 1, 8, 21, 40; centered Cn(8)C_n^{(8)} gives 1, 9, 25, 49 (the odd squares). Very different sequences.

Misapplying the discriminant. The correct discriminant for octagonals is 3m+13m + 1. Using 8m+18m + 1 (triangular), 24m+124m + 1 (pentagonal), or 40m+940m + 9 (heptagonal) gives wrong results.

Off-by-one in arithmetic series. The series is 1,7,13,19,1, 7, 13, 19, \ldots with general term 6k56k - 5 (where kk starts at 1). Writing 6k+16k + 1 or 6k16k - 1 gives different sequences.

Confusing polygonal index with side count. OnO_n is the nn-th octagonal number, not the count of dots in an octagon with side nn (though they happen to coincide for the polygonal definition; the indexing can be subtle).

Related Sequences and Concepts

Triangular NumbersTn=n(n+1)/2T_n = n(n+1)/2. The r=3r = 3 polygonal sequence.

Square NumbersSn=n2S_n = n^2. The r=4r = 4 polygonal sequence.

Pentagonal NumbersPn=n(3n1)/2P_n = n(3n-1)/2. The r=5r = 5 polygonal sequence; features in Euler's theorem.

Hexagonal NumbersHn=n(2n1)H_n = n(2n-1). The r=6r = 6 polygonal sequence; equals odd-indexed triangulars.

Heptagonal NumbersHpn=n(5n3)/2\mathrm{Hp}_n = n(5n-3)/2. The r=7r = 7 polygonal sequence.

Centered Octagonal Numbers(2n1)2(2n-1)^2 — the odd squares. A distinct sequence with concentric-ring geometry.

Polygonal Numbers — the general rr-gonal family. Octagonal is the r=8r = 8 member.

Fermat's Polygonal Number Theorem — every positive integer is a sum of at most 8 octagonal numbers. The general statement: every positive integer is a sum of at most rr rr-gonal numbers, proved by Cauchy.

Arithmetic SeriesOn=k=1n(6k5)O_n = \sum_{k=1}^{n}(6k - 5). The sum of an arithmetic series with a1=1a_1 = 1 and d=6d = 6.

Figurate Numbers — the umbrella family.

Star Number — a related sequence (6n26n+16n^2 - 6n + 1) sometimes confused with octagonal but distinct; gives 1, 13, 37, 73, 121, ...

Octagonal Pyramidal Numbers — the 3D analog: n(n+1)(2n1)/2n(n+1)(2n - 1)/2 wait, actually the formula is more involved. They count dots in an octagonal pyramid.

Generalized Polygonal Numbers — extension where indexes can be negative; less famous for octagonals than for pentagonals.