CCalclabhub

Math · 93 calculations

Geometry

How To Calculate The Number Of Diagonals In A Polygon

Counting diagonals is a compact lesson in avoiding double counting. From any vertex of a convex polygon you can join every other vertex except the vertex itself and its two neighbours, and dividing by two then gives the total. The answer depends only on the number of sides and grows quadratically, so doubling the sides produces far more than twice as many diagonals.

Last updated

Quick Answer

D = n(n - 3) / 2

n
Number of sides, equal to the number of vertices
n - 3
Diagonals that can be drawn from a single vertex
D
Total number of distinct diagonals in the polygon

From each of the n vertices you can draw n - 3 diagonals, because a vertex cannot join to itself or to either adjacent neighbour. Multiplying n by n - 3 counts every diagonal from both ends, so divide by two. An octagon has 8 x 5 / 2 = 20 diagonals, while doubling the sides to sixteen gives 104.

What Is The Number Of Diagonals In A Polygon?

A diagonal is a straight segment that joins two vertices of a polygon without being one of its edges. The two endpoints must be non-adjacent, because a join between neighbours is simply another side. What is striking is that the count depends on nothing but the number of vertices: the shape can be stretched, skewed or rotated and the total stays the same. This page assumes a convex polygon, where every such segment lies wholly inside the boundary. For a concave polygon some of the same vertex pairs produce segments that pass outside the shape, so the formula counts vertex pairs rather than guaranteed interior lines.

Start with a single vertex. From it you can reach every other vertex, but three of those destinations do not produce a diagonal. The vertex cannot join to itself, and joining it to either of its two immediate neighbours recreates an existing side. That leaves n minus three possible diagonals from each vertex. For an octagon the figure is eight minus three, or five, diagonals per corner. This small subtraction is the source of the three in the numerator of the main formula.

Multiplying the per-vertex count by n gives n times n minus three, but this is not yet the answer. Every diagonal has two ends, so the walk around the vertices meets each diagonal exactly twice: once starting at one endpoint and once starting at the other. Dividing the product by two removes that duplication. The division is always exact, because n times n minus three is even: if n is even the first factor is even, and if n is odd then n minus three is even. An octagon therefore has eight times five divided by two, which is twenty.

Small cases make a useful check. A triangle has three vertices and no possible non-adjacent pair, so it has zero diagonals. A quadrilateral has two, crossing near the centre, and a pentagon has five, which is why joining every vertex to every other one draws a five-pointed star. A hexagon has nine, an octagon twenty and a twelve-sided dodecagon fifty-four. If your calculation disagrees with any of these anchors, the error is in the algebra rather than the geometry.

The growth is quadratic, not linear. Doubling the number of sides from eight to sixteen does not merely double the count from twenty to forty: it produces sixteen times thirteen over two, which is one hundred and four. That is more than five times as many diagonals from only twice as many vertices. The reason is that each new vertex can connect to all the older non-neighbouring vertices, so the pool of possible pairs expands faster than the list of corners. Any estimate that assumes simple proportionality will badly understate large polygons.

There is a second way to reach the same result, and it explains the factor of two from a different direction. Choose any pair of vertices and you have either a side or a diagonal. There are n times n minus one over two possible pairs in total. Exactly n of them are sides, so subtracting n leaves the diagonals. For an octagon this is twenty-eight pairs minus eight sides, giving twenty again. The two derivations are algebraically identical, but the pair-counting version makes the source of the division by two particularly clear.

Diagonals also describe how a polygon can be broken into triangles. Draw all five diagonals from one corner of an octagon and the interior is divided into six triangles, which is n minus two. A triangulation of a convex polygon always uses n minus three diagonals and creates n minus two triangles, whatever order you draw them in. This is the relationship behind many area algorithms and behind the familiar formula for the sum of interior angles. It is a different question from counting every diagonal, but the same two subtractions appear in both.

The count turns up well beyond geometry exercises. A mesh generator needs to know how many internal connections a polygonal cell contributes before it can estimate memory use. Network and scheduling problems use the same pair-counting logic: a group of n participants has n times n minus one over two possible pairwise links. Removing the n links that are not allowed leaves the permitted ones. Recognising the shared structure means one formula serves graph theory, computer graphics and combinatorics without modification.

The formula has clear limits, and stating them avoids misapplication. The input must be a whole number of at least three, since a polygon with fewer sides does not exist. The count tells you how many diagonals there are, not how long they are or where they cross, so questions about intersection points need extra work. A diagonal of a rectangle is a special case of the same idea: a quadrilateral has two of them, and their length comes from a separate calculation. Keep the counting question distinct from the measurement question and the arithmetic stays clean.

Formula

D = n(n - 3) / 2

Formula page →

Each vertex offers n - 3 diagonals, and multiplying by n counts each one twice, so the product is halved.

SymbolMeaning
nNumber of sides
n - 3Diagonals from one vertex
DTotal distinct diagonals

D = n(n - 1) / 2 - n

Formula page →

Every pair of vertices is either a side or a diagonal, so subtract the n boundary sides from the total number of pairs.

SymbolMeaning
n(n - 1) / 2All unordered vertex pairs
nBoundary sides
DTotal distinct diagonals

d = n - 3; t = n - 2

Formula page →

The diagonals from one corner number n - 3, and drawing all of them splits the polygon into n - 2 triangles.

SymbolMeaning
dDiagonals from one vertex
tTriangles in the triangulation
nNumber of sides

How To Calculate The Number Of Diagonals In A Polygon

  1. 1

    Count the vertices

    Write down n, the number of sides, which equals the number of vertices for any simple polygon. Confusing sides with corners is rare here because they match exactly, but counting the vertices of a drawn shape by eye is a common source of an off-by-one error.

  2. 2

    Subtract three for the per-vertex count

    From one corner you cannot draw a diagonal to itself or to either neighbour, so the available destinations number n - 3. For an octagon that is 8 - 3 = 5. This is the only subtraction in the method, and it is easy to check by listing the reachable corners on a sketch.

  3. 3

    Multiply by the number of vertices

    Compute n x (n - 3), which totals the diagonals as seen from every corner. For the octagon this is 8 x 5 = 40. The product is deliberately too large, because every segment has been encountered at each of its two ends.

  4. 4

    Divide by two to remove the double count

    Halve the product to obtain D = n(n - 3) / 2. The octagon gives 40 / 2 = 20. The result is always a whole number: if n is even then n is even, and if n is odd then n - 3 is even.

  5. 5

    Check against a known case and note the growth

    Compare with the anchors: 0 for a triangle, 2 for a quadrilateral, 5 for a pentagon and 9 for a hexagon. Then remember the scaling — going from 8 sides to 16 raises the count from 20 to 104, a factor of 5.2, because the formula is quadratic rather than proportional.

Examples

Example 1: Octagon — eight sides

sides
8
StepCalculationResult
Number of sidesn8
Diagonals from each vertex8 - 35
Counted from both ends8 x 540
Distinct diagonals40 / 220

Result: An octagon has 20 diagonals, five from each of its eight vertices before the double counting is removed.

Example 2: Hexagon — six sides

sides
6
StepCalculationResult
Number of sidesn6
Diagonals from each vertex6 - 33
Counted from both ends6 x 318
Distinct diagonals18 / 29

Result: A hexagon has 9 diagonals, which is also what choosing 6 side pairs and subtracting the 6 sides gives.

Example 3: Dodecagon — twelve sides

sides
12
StepCalculationResult
Number of sidesn12
Diagonals from each vertex12 - 39
Counted from both ends12 x 9108
Distinct diagonals108 / 254

Result: A dodecagon has 54 diagonals, more than double the 20 of an octagon because the growth is quadratic.

Calculator

Total diagonals

20

Diagonals from one vertex
5
Diagonals at twice the sides
104
Triangles from one vertex
6

Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.

Prefer a full-width tool? Open the The Number Of Diagonals In A Polygon calculator page.

Common Mistakes

  • Forgetting to divide by two

    Reporting n(n - 3) directly doubles the answer: 40 instead of 20 for an octagon. Each diagonal joins two vertices and is therefore encountered twice when you walk around the corners.

  • Subtracting two instead of three per vertex

    A vertex cannot join to itself as well as to its two neighbours, so there are three exclusions, not two. Using n - 2 gives 48 divided by two for an octagon rather than the correct 20.

  • Assuming the count grows in proportion to the sides

    Doubling the sides from eight to sixteen takes the diagonals from 20 to 104, not to 40. The n(n - 3) product makes the relationship quadratic, so linear extrapolation is badly wrong for larger shapes.

  • Counting a side as a diagonal

    Joining two adjacent vertices traces the boundary edge, not a diagonal. If you count every vertex pair with n(n - 1) / 2 and forget to remove the n sides, a pentagon appears to have 10 diagonals instead of 5.

  • Using a fractional or negative side count

    The formula is meaningful only for whole n of at least three. Substitute 3.5 or a negative value and the algebra still produces a number, but it describes no polygon and should be rejected at the input stage.

  • Confusing the count with a diagonal length

    The formula answers how many diagonals exist, not how long any one of them is. A quadrilateral has two diagonals, but their lengths require the Pythagorean theorem or trigonometry and a separate calculation.

FAQ

Why do we subtract three from the number of sides?

From a given vertex, three destinations are ruled out: the vertex itself and the two adjacent vertices. A join to a neighbour is just a boundary side, and a join to itself is not a segment at all. Everything else is a diagonal, leaving n - 3 choices.

Why divide the product by two?

Every diagonal has two endpoints. When you count n - 3 diagonals from each of the n vertices, the same segment is recorded once from each end. Halving the total of n(n - 3) removes that duplication and leaves each segment counted exactly once.

How many diagonals does a triangle have?

None. With n = 3 the formula gives 3 x 0 / 2 = 0. Every pair of vertices in a triangle is already a side, so there is no non-adjacent pair to join. The triangle is the smallest polygon and the natural lower anchor for the formula.

Does the formula work for concave polygons?

It counts pairs of non-adjacent vertices, which is still well defined. However, in a concave polygon some of those segments pass outside the boundary, so they are not always diagonals in the strict interior sense. The usual statement assumes a convex polygon.

What is the link between diagonals and triangles?

Drawing all n - 3 diagonals from a single vertex divides a convex polygon into n - 2 triangles. That is the basis of triangulation and of the interior-angle sum. It is a related count, but it is not the total number of diagonals.

What happens to the count when the sides are doubled?

It grows by much more than a factor of two because the formula is quadratic. An octagon has 20 diagonals and a sixteen-sided polygon has 104, a factor of 5.2. In general, doubling n changes the count from n(n - 3) / 2 to n(2n - 3).

References

  1. [1]Wikipedia, Polygon — https://en.wikipedia.org/wiki/Polygon
  2. [2]Wikipedia, Diagonal — https://en.wikipedia.org/wiki/Diagonal
  3. [3]Wikipedia, Vertex (geometry) — https://en.wikipedia.org/wiki/Vertex_(geometry)