Key Points
The diagonals formula is , giving the number of diagonals in a polygon with sides.
The OEIS records that for is the number of diagonals of an -gon.
Each vertex joins to others, excluding itself and its two neighbours, which is where the comes from.
The division by 2 is needed because counting from every vertex names each diagonal twice, once from each end.
A triangle has zero diagonals, which the formula returns correctly since .
What Is the Diagonals Formula?
The diagonals formula counts how many diagonals a polygon has from its number of sides:
A diagonal is a line segment joining two non-adjacent vertices. The On-Line Encyclopedia of Integer Sequences records that for gives the number of diagonals of an -gon.
This article covers only that count. For the length of a diagonal in a specific shape, see the diagonals page, which deals with diagonal segments and their measurements rather than how many exist.
Why the Formula Is n Times n Minus 3, Halved
Pick any vertex of an -sided polygon. It cannot join to itself, and joining to either of its two neighbours produces a side rather than a diagonal, so it has possible diagonals.
Doing that from every vertex gives segments. But each diagonal has two endpoints and gets counted once from each, so the true total is half that figure.
A second route reaches the same place. The number of segments joining any two of the vertices is , and removing the sides leaves .
Variable Key
Symbol | Meaning | Unit or type | Notes |
|---|---|---|---|
number of sides | integer, at least 3 | also the number of vertices | |
diagonals from one vertex | count | excludes itself and two neighbours | |
endpoint count | count | each diagonal counted twice | |
number of diagonals | whole number |
Examples of the Diagonals Formula
Example 1
How many diagonals does a hexagon have?
Final answer: 9 diagonals
Example 2
How many diagonals does an octagon have, counting from every vertex without halving?
Each of the 8 vertices reaches others, so counting from every vertex gives
That 40 is too large, and the reason is visible on a drawing. The diagonal from vertex A to vertex D gets counted once when working from A and again when working from D, so every diagonal appears twice in the total.
Halving corrects it:
Final answer: 20 diagonals
Example 3
How many diagonals does a triangle have?
Final answer: 0
Every pair of vertices in a triangle is adjacent, so no diagonal exists. The formula returns this correctly rather than breaking down.
Example 4
A polygon has 35 diagonals. How many sides does it have?
Set the formula equal to 35 and solve:
Final answer: , a decagon. The root is discarded as a side count cannot be negative.
Example 5
How many diagonals does a 20-sided polygon have?
Final answer: 170 diagonals
The count grows roughly with the square of the number of sides, which is why diagonals multiply so quickly on larger polygons.
Don't Confuse the Diagonal Count With These Three
Quantity | Formula | What it gives |
|---|---|---|
Number of diagonals | how many diagonals exist | |
All vertex pairs | diagonals plus sides | |
Diagonals from one vertex | the count at a single corner | |
Length of a diagonal | varies by shape | a measurement, not a count |
The last row is a different question entirely. A square's diagonal length is , and that has nothing to do with how many diagonals a square has, which is 2.
Where Intuition Breaks on the Diagonals Formula
Mistake 1: Forgetting to halve
Where it slips in: Counting from each of vertices is the natural first move, and the result looks like a finished total.
Don't do this:
The correct way: . Each diagonal has two ends and is counted once from each.
Students who draw a pentagon and count its diagonals by hand, getting 5, then test both candidate formulas against that number, never forget the halving. Verifying a counting formula on the smallest case you can draw is the quickest structural check there is.
Mistake 2: Using n minus 2 instead of n minus 3
Where it slips in: Excluding the vertex itself and one neighbour gives , and the second neighbour is easy to overlook.
Don't do this:
The correct way: Three vertices are unavailable from any starting vertex: itself and both neighbours. On a hexagon that leaves 3 diagonals per vertex, not 4.
Mistake 3: Applying the formula to a non-polygon or to a shape with fewer than 3 sides
Where it slips in: The formula is algebraic, so it returns values for and .
Don't do this: Compute for and report 1.
The correct way: The formula holds for , as the OEIS entry states. Below three sides there is no polygon, so the output is meaningless rather than merely wrong.
Bottom Line
The diagonals formula is for a polygon with sides.
The comes from excluding the vertex itself and its two neighbours.
The halving removes the double count, since each diagonal is reached from both of its ends.
The formula holds from upwards, correctly returning zero diagonals for a triangle.
To work through polygon geometry with a teacher, explore a geometry tutor or math tuition.
Where to Go From Here
Find the number of diagonals in a pentagon and a dodecagon. Then work out how many sides a polygon has if it holds 54 diagonals.
Want a live Bhanzu trainer to walk through more geometry problems? Book a free demo class.
Read More
Was this article helpful?
Your feedback helps us write better content