Number Theory
Intermediate

Sum of First n Squares

Closed form for the sum of the first n squares.

Formula

k=1nk2=n(n+1)(2n+1)6\sum_{k=1}^{n} k^2 = \frac{n(n+1)(2n+1)}{6}

Variables

nUpper limit

Example

1² + 2² + 3² = 3·4·7/6 = 14. ✓

Did You Know?

The sum of the first n squares appears in physics when computing moments of inertia.