Polygon diagonals calculator

Enter an integer number of vertices n (n ≥ 3). The number of diagonals of a convex n-gon is D = n(n − 3)/2. A quadrilateral (n = 4) gives 2. A pentagon (n = 5) gives 5. A hexagon (n = 6) gives 9. A triangle (n = 3) gives 0. The calculator returns the count of diagonals, not their lengths or the angle sum.

Input

Result

Enter an integer n ≥ 3.

The calculator counts how many diagonals there are, not how long they are. n must be an integer at least 3. For n = 3 the result is 0; a fractional n is rejected.

How it works

How D is computed for n = 6
n6
n(n−3)18
D9

A diagonal of a convex polygon is a segment joining two vertices that are not neighbors on the boundary. Sides are not diagonals. The count of such segments in an n-gon is a classic school-geometry and discrete-combinatorics result: D = n(n − 3)/2 for an integer n ≥ 3. The same formula appears in standard discrete-mathematics texts when counting edges of graphs and in geometry references on polygon diagonals.

Vertex derivation: from a fixed vertex you can connect to n − 1 others. Two of them are neighbors (sides), so n − 3 diagonals remain. Across n vertices you get n(n − 3) “ends.” Each diagonal has two ends, so you divide by 2 to obtain D.

Combinatorial derivation: the number of all vertex pairs is C(n,2) = n(n − 1)/2. Of those, n pairs are the polygon sides. The rest are diagonals: D = C(n,2) − n = n(n − 3)/2. Equivalently: edges of the complete graph Kₙ minus the n cycle edges. For n = 6: C(6,2) = 15, sides = 6, D = 9.

The calculator uses the single number n that you enter. The result D is a non-negative integer. Worked values: triangle n = 3 → 0; quadrilateral n = 4 → 2; pentagon n = 5 → 5; hexagon n = 6 → 9; heptagon n = 7 → 14; octagon n = 8 → 20; decagon n = 10 → 35. Fractional n and n < 3 are rejected — the algebraic expression for n = 2 equals −1, but that does not describe a polygon.

This calculator does not compute diagonal lengths, areas, or angle sums. The interior-angle sum (n − 2)×180° lives on a related page and uses the same n for a different result. The diagram draws a regular n-gon with diagonals for n up to 16; beyond that the count still comes from D = n(n − 3)/2.

In school and contest problems the formula gives a quick diagonal count and supports tournament-style counting (matches = edges of Kₙ). In graphics and CAD, a fan triangulation of a convex n-gon uses n − 3 diagonals from one vertex (n − 2 triangles). Here the result is only the total number of diagonals.

Formula

D = n(n − 3) / 2, where n ∈ ℕ, n ≥ 3.

Equivalently: D = C(n,2) − n = n(n − 1)/2 − n. The symbol n is the number of vertices (and sides) of a convex polygon. The symbol D is the diagonal count. C(n,2) is the number of vertex pairs, i.e. the edges of the complete graph Kₙ.

Mathematical model: number of diagonals of a convex n-gon (standard school / combinatorial formula), matching polygon-diagonal theorems and discrete-mathematics counting (Rosen and graph textbooks).

Theory and full derivation

Definition

The number of diagonals of a convex (or simple) polygon with n vertices, n ≥ 3, is the number of segments joining two non-adjacent vertices. The combinatorial formula is D = n(n − 3)/2. Each vertex connects by diagonals to n − 3 others (all except itself and its two neighbours); summing n(n − 3) counts each diagonal twice, hence the division by 2.

For a triangle (n = 3) one obtains D = 0 — no diagonals. For a quadrilateral D = 2, for a pentagon D = 5, for a hexagon D = 9. MathWorld (Polygon Diagonal) gives the same formula. In Euclidean geometry, diagonals of a convex polygon lie inside the figure; with concavity some may go outside, but the vertex-pair counting formula remains the same. The calculator reports that combinatorial count for integer n ≥ 3.

Historical and conceptual context

Counting diagonals belongs to elementary geometric combinatorics and appears in classical school exercises and in Euclid’s Elements in the context of dissecting polygons into triangles. The number of ways to choose 2 vertices among n is C(n, 2) = n(n − 1)/2; among them n are sides, so the number of diagonals is C(n, 2) − n = n(n − 3)/2.

Conceptually D is a nonnegative integer. The calculator takes n as an integer ≥ 3; non-integers or n < 3 do not describe a polygon in this sense. The formula does not depend on side lengths or on regularity — only on the number of vertices and adjacency on the cycle. Side lengths and angles affect geometry, not this discrete count.

Formal properties

Domain: n ∈ ℤ, n ≥ 3. Result: D = n(n − 3)/2 ∈ {0, 1, 2, …}. Sequence: 0, 2, 5, 9, 14, 20, … (for n = 3, 4, 5, 6, 7, 8, …). Increment: D(n+1) − D(n) = n − 1 — adding a vertex adds n − 1 new diagonals after the cycle is updated.

Equivalent forms: D = C(n, 2) − n; D = (n² − 3n)/2. For a regular polygon the same D diagonals can be drawn in the circumscribed circle; interior intersections are a separate problem (number of crossing points), which this formula does not solve.

Triangulation: a convex n-gon splits into n − 2 triangles via n − 3 non-crossing diagonals from one vertex — a different count from D (the total number of all diagonals). Full D also includes diagonals that cross inside.

Full derivation of the formula D = n(n − 3)/2

Step 1. A polygon has n vertices joined in a cycle: each has exactly two neighbours along the boundary.

Step 2. From a fixed vertex one can draw a segment to n − 1 other vertices. Two of them are sides; so the number of diagonals from one vertex is n − 3.

Step 3. Summing over all vertices: n(n − 3). Each diagonal has two endpoints, so it was counted twice. Hence D = n(n − 3)/2.

Step 4 (combinatorial variant). The number of all segments among vertices is C(n, 2). Subtract n sides: C(n, 2) − n = n(n − 1)/2 − n = n(n − 3)/2. Both derivations are equivalent and standard in MathWorld and discrete-geometry texts.

Special cases

n = 3: D = 0. n = 4: D = 2 (quadrilateral diagonals). n = 5: D = 5. n = 6: D = 9. n = 10: D = 35. n = 100: D = 4850. Parity check: n(n − 3) is always even for integer n ≥ 3, so D is an integer.

As n grows, D grows quadratically (~ n²/2). For large n drawing all diagonals becomes dense; the formula still gives the correct count, independent of visualization. For n < 3 the formula may formally give a negative or fractional value — outside the model domain.

Numerical and computational notes

Computation: D = n * (n - 3) / 2 for integer n ≥ 3. In a computer program prefer integer arithmetic or check that n is an integer. Division by 2 is exact when n(n−3) is even — always for integer n.

Non-integer input should be rejected or rounded only if the page clearly says so; this model assumes a vertex count. Comma/period do not change the meaning if the value must be integral. For very large n the result may exceed the largest exactly representable integer (2⁵³ − 1) — then big-integer arithmetic is needed.

Related concepts and authorities

Related tools: sum of interior angles ((n−2)·180°), number of triangles in a triangulation (n−2), perimeter and area of a regular polygon. The diagonal count does not depend on the circumradius — unlike side lengths.

Authorities: Euclid, Elements (polygons and dissections); MathWorld — Polygon Diagonal; combinatorics: C(n, 2) − n; standard school geometry texts. The calculator does not replace an exam proof — it evaluates D = n(n−3)/2. A useful cross-check is to compute C(n, 2) and subtract n sides: the difference must equal the displayed diagonal count for every integer n ≥ 3.

How to use

  1. Enter an integer vertex count n, for example 6.
  2. Click Calculate or wait for the live result. n = 6 gives 9 diagonals.
  3. Check the panel: D, n − 3 from one vertex, C(n,2), and the C(n,2) − n check.
  4. The diagram draws a regular n-gon with diagonals (up to n = 16). Examples fill the field and refresh the drawing.
  5. n < 3 or a fraction fails. Diagonal length and angle sum live on other pages.

Symbol glossary

D = n(n − 3)/2 is the diagonal count of a convex n-gon. n = 4 gives 2. n = 5 gives 5. n = 6 gives 9.

D
Number of diagonals. Primary result. For n = 6 it equals 9.
n
Integer number of vertices (and sides), n ≥ 3. The single form field.
n − 3
Diagonals from one vertex. For a hexagon: 3.
C(n,2)
n(n − 1)/2 — edges of Kₙ. D = C(n,2) − n.

Examples

Example 1

  • n: 4

2

How many diagonals does a quadrilateral have? 2.

Example 2

  • n: 5

5

How many diagonals does a pentagon have? 5.

Example 3

  • n: 6

9

How many diagonals does a hexagon have? 9.

Example 4

  • n: 3

0

How many diagonals does a triangle have? 0.

Example 5

  • n: 7

14

How many diagonals does a heptagon have? 14.

Example 6

  • n: 8

20

How many diagonals does an octagon have? 20.

Example 7

  • n: 10

35

How many diagonals does a decagon have? 35.

Example 8

  • n: 12

54

How many diagonals does a dodecagon have? 54.

Related calculators

Frequently asked questions

What is the formula and domain for the number of diagonals?

For a convex n-gon the number of diagonals is D = n(n − 3)/2, where n is an integer and n ≥ 3. That is the standard school and combinatorial formula: each vertex sends n − 3 diagonals, and dividing by 2 removes double counting.

How many diagonals does a quadrilateral have?

Two. With n = 4: D = 4×(4 − 3)/2 = 2. That is the first worked example on this page and the same fill from “Fill this example”.

How many diagonals does a triangle have?

Zero. With n = 3: D = 3×0/2 = 0, because every vertex is adjacent to the other two — there is no non-adjacent pair.

How many diagonals do a pentagon and a hexagon have?

A pentagon (n = 5) has 5 diagonals. A hexagon (n = 6) has 9. Those are examples 2 and 3 on this page.

Is the result a diagonal length?

No. The calculator returns the count of diagonals, not their lengths. Length would need side lengths or coordinates; the only input here is n.

Why does the formula divide by 2?

From each of the n vertices you draw n − 3 diagonals, for n(n − 3) directed ends in total. Each diagonal has two ends, so it appears twice in that product. Dividing by 2 gives the number of distinct diagonals.

Does n have to be an integer?

Yes. A polygon has a whole number of vertices. A fraction such as 4.5 does not describe an n-gon on paper — the calculator rejects that input instead of multiplying blindly.

How does this relate to the complete graph Kₙ?

The complete graph Kₙ has C(n,2) = n(n − 1)/2 edges. Of those, n are the polygon sides and the rest are diagonals: C(n,2) − n = n(n − 3)/2. The result panel shows that check beside D.

How is this different from the polygon angle sum?

Here the result is a count of segments (diagonals). The interior-angle sum is (n − 2)×180° — same n, different quantity. Use the related angle-sum page for degrees.

What happens at n = 2?

The expression n(n − 3)/2 equals −1, but n = 2 is not a polygon. The calculator requires n ≥ 3 and shows an error instead of a negative “result”.

How many diagonals leave one vertex?

Exactly n − 3. You skip yourself and the two neighbors on the boundary. For a hexagon that is 3; for a decagon, 7.

Do the currency and unit settings in the page header affect the result?

No. The result depends only on an integer n ≥ 3. The currency and unit settings in the page header do not affect this result.

How do I calculate the number of diagonals in a polygon?

Use D = n(n − 3)/2 with integer n ≥ 3. For n = 6: 6·3/2 = 9. Equivalently D = C(n,2) − n.

How many diagonals does an octagon have?

20. Computation: 8·(8 − 3)/2 = 40/2 = 20. That is Example 6 on this page.

How many diagonals does a decagon have?

35. Computation: 10·7/2 = 35. That is Example 7 on this page.

Is the result the length of a square or rectangle diagonal?

No. This page only counts segments between non-adjacent vertices. Diagonal lengths of specific shapes belong on separate calculators.

How many diagonals does a 100-gon have?

4850. Computation: 100·97/2 = 4850. Enter n = 100 to see the result in the panel.

For n = 6 the result is D = 9. Check: C(6,2) − 6 = 15 − 6 = 9. Angle sum from the same n is on the sum of polygon angles page.

Sources

The formula, derivation, and examples below come from established geometry and combinatorics references.

Page Updated November 2, 2026.