Square Pyramidal Number Calculator

Find any square pyramidal number Pₙ.

How it is calculated

The n-th square pyramidal number is Pn = n × (n + 1) × (2n + 1) ÷ 6, which equals the sum 1² + 2² + … + n². Here n is the number of layers of the pyramid, counted from the single ball on top down to the base layer of n × n balls. The input is cut to a whole number, so 3.7 is treated as 3, and it must be between 0 and 100,000. Negative values and values above 100,000 give no result. n = 0 gives 0, an empty pyramid. The answer is an exact whole number, shown with thousands separators, and the formula is used directly rather than adding the squares one by one.

Worked example

A pyramid of 10 layers has a 10 × 10 layer at the bottom, then 9 × 9, and so on up to a single ball at the top. Using the formula: 10 × 11 × 21 = 2,310, and 2,310 ÷ 6 = 385. As a check, add the squares: 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 = 385. So 385 equal spheres are needed to build the pyramid.

Try this example →

Common mistakes

  • Confusing it with a square number or with a triangular number. Pn is the running total of squares, so P10 is 385, while 10² is only 100.
  • Entering the number of balls in the base layer as the number of balls you have. The input is the number of layers n, not the total; to find the layers for a given stock, try n values until Pn reaches your total.
  • Using the formula for a pyramid with a different base. A triangular base gives tetrahedral numbers, and this tool covers only a square base.
  • Typing a decimal and expecting interpolation. Layers are whole, so 3.7 is read as 3 and the result is 14, not a value between 14 and 30.
  • Starting the count at the wrong layer. The top ball counts as layer 1, so a pyramid of 3 layers has 1 + 4 + 9 = 14 balls and not 4 + 9.

About this calculator

The nth square pyramidal number Pₙ = n(n+1)(2n+1)/6 is the sum of the first n perfect squares (1² + 2² + … + n²), representing the number of spheres that stack into a pyramid with a square base n layers tall — one layer of n² balls, the next of (n−1)², and so on down to a single ball on top.

These numbers are famous in number theory for the cannonball problem: the question of when a square pyramidal stack can be rearranged into a flat square array, which turns out to happen only for n=1 and n=24 (1+4+9+…+24² = 4900 = 70²), a result proved using elliptic curves. Mathematics educators use square pyramidal numbers to teach summation formulas, and puzzle enthusiasts encounter them in classic stacking problems.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Square pyramidal numbers hide a famous curiosity: apart from 1, only P24 = 4,900 is also a perfect square, namely 70 squared, which means 4,900 balls could be stacked as a pyramid and also laid out as a square. You can confirm it by typing 24. The input is cut to a whole number. If you use this for a physical stack, what are you stacking?

Popular calculators

All Calculators