Sum of Consecutive Squares Calculator
Compute the sum of squares across a number range and get the total, useful for algebra formulas, variance work, and series practice.
Enter the Details
Result will appear here...
What this calculator does
This adds up the squares of a run of whole numbers. Give it a start and an end, and it works out 12 + 22 + 32 and so on across the range, without you squaring and adding a thing.
And like its cousin the sum of cubes, it hides a rather charming picture, which is coming up next. It runs right here in the browser.
Using the calculator
- Enter the first number (n1), the start of the range.
- Enter the second number (n2), the end of the range.
- Press Calculate.
It returns the sum of the squares from n1 to n2. Use whole numbers, with n1 no bigger than n2. Reset clears both boxes.
The picture behind it: a pyramid of cannonballs
Picture stacking cannonballs into a pyramid with a square base. The bottom layer is a square, say 5 by 5, so 25 balls. The layer above is 4 by 4, so 16. Then 9, then 4, then a single ball on top. The total number of cannonballs in the whole stack is 25 + 16 + 9 + 4 + 1, which is exactly the sum of the squares from 1 to 5.
That is not a coincidence, it is the whole idea. The sum of the first n squares is the number of balls in a square pyramid n layers tall, and for that reason these totals are called the square pyramidal numbers: 1, 5, 14, 30, 55, and on up.
The formula, and the range version
Rather than adding layer by layer, there is a closed form for the sum of the first n squares:
sum of first n squares = n(n + 1)(2n + 1) ÷ 6
To total the squares over a range that does not start at 1, the tool totals up to n2 and subtracts the total up to just before n1: n2(n2 + 1)(2n2 + 1) ÷ 6 minus (n1 − 1)n1(2n1 − 1) ÷ 6. What is left is precisely the squares from n1 to n2.
A worked example
Sum the squares from 1 to 5.
- By adding: 12 + 22 + 32 + 42 + 52 = 1 + 4 + 9 + 16 + 25 = 55.
- By the formula: 5 × 6 × 11 ÷ 6 = 330 ÷ 6 = 55. They match, and 55 is the fifth square pyramidal number.
For a range like 2 to 4, take the sum to 4 and remove the sum to 1: 30 − 1 = 29, which is 4 + 9 + 16.
A question asked at sea
This one has a story attached. In the late 1500s, the explorer Sir Walter Raleigh reportedly asked the mathematician Thomas Harriot, while the two were on a sea voyage, how to count the cannonballs in a pyramidal stack without counting them one by one. Harriot worked on exactly the problem this formula solves. It is a nice reminder that a piece of maths that looks purely abstract, a sum of squares, started life as a very practical question about how much ammunition was on deck.
Questions people ask
What is the formula for the sum of squares?
The sum of the first n squares is n(n + 1)(2n + 1) ÷ 6.
What are square pyramidal numbers?
They are the sums of squares, 1, 5, 14, 30, 55, and they count the cannonballs in a square-based pyramid with that many layers.
Can I sum squares over a range, not just from 1?
Yes. The tool totals the squares up to your end value and subtracts the total up to just before your start value.
Is this related to the sum of cubes?
They are cousins, both sums of powers with elegant closed forms. The sum of cubes has its own surprise: it equals the square of the plain sum.
Why is there a divide by 6 in the formula?
It falls out of the algebra when the sum is worked out, and it is what makes n(n + 1)(2n + 1) always come out to a whole number, since that product is always divisible by 6.
References
A note on where this comes from. The sum of the first n squares equals n(n + 1)(2n + 1) ÷ 6, a classical result whose totals are the square pyramidal numbers, the counts of spheres stacked in a square pyramid. It is a special case of Faulhaber's formula for sums of powers. For further reading, see Square pyramidal number.
- The square pyramidal numbers, the sums of squares, given by n(n + 1)(2n + 1) ÷ 6, OEIS sequence A000330. https://oeis.org/A000330
- Faulhaber's formula, the general expression for the sum of the pth powers of the first n whole numbers, of which the sum of squares is the case p = 2.
Okan Atalay is a results driven senior operations manager and a graduate of Industrial Engineering from Bilkent University. With over 22 years of experience in textile manufacturing and integrated operations, he has led large scale business process improvements and strategic planning initiatives. Currently, he serves as a top mathematics expert for a global ed tech platform, where he applies his analytical expertise to solve complex mathematical problems. At Eon Tools, he reviews converter and maths tools.