Diagonals of Polygons

A polygon's diagonals are line segments from one corner to another (but not the edges).

Square showing 2 intersecting diagonal lines connecting opposite corners
A square has
2 diagonals
Regular octagon with all 20 of its diagonals drawn, forming a star pattern inside
An octagon has
20 diagonals

The number of diagonals of an n-sided polygon is:

n(n − 3) / 2

Why does this work?

  • Each of the n corners joins to (n − 1) other corners
  • Two of those are edges, so there are (n − 3) diagonals from each corner
  • That seems like n(n − 3) diagonals, but each diagonal is counted twice (once from each end),
  • so we divide by 2: n(n − 3) / 2

Examples:

  • a square (or any quadrilateral) has 4(4−3)/2 = 4×1/2 = 2 diagonals
  • an octagon has 8(8−3)/2 = 8×5/2 = 20 diagonals
  • a triangle has 3(3−3)/2 = 3×0/2 = 0 diagonals

Try it Yourself:

images/area-coords.js?mode=diag
Concave polygon where one red diagonal line segment is located completely outside the shape

A diagonal can actually be outside the polygon,
which happens with some concave polygons

Handy Table

Number of diagonals for the first few polygons:

Polygon Sides (n) Diagonals
Triangle 3 0
Quadrilateral 4 2
Pentagon 5 5
Hexagon 6 9
Heptagon 7 14
Octagon 8 20
Nonagon 9 27
Decagon 10 35
1794, 7625, 7627, 7629, 11, 1795, 7626, 7628, 7630, 7631