I'm trying to find a general expression for the number of adjacent edges in a $n \times n$ grid of uniform squares.

A square can have adjacent edges above, below, to the left, or to the right, if there is another square there. No diagonals.

So for example, a

a) $2\times2$ grid has $4$ squares and $4$ adjacent edges,

b) $3\times3$ grid has $9$ squares and $12$ adjacent edges,

c) $4\times4$ grid has $16$ squares and $24$ adjacent edges,

and so on.

It seems really simple but I can't seem to find a correct generalization.

## Best Answer

There are $n$ adjacent edges in each horizontal line segment and there are $n-1$ such line segments. This leads to a total of $n(n-1)$ $\color{red}{\text{horizontal adjacent edges}}$. And since a square is symmetric, there are an equal number of $\color{blue}{\text{vertical adjacent edges}}$ too. Therefore, the total number of adjacent edges in a $n\times n$ grid is given by: $$ 2n(n-1)$$