A square number is the count of dots needed to form a square of side n. Starting with one dot and adding a border of dots each step:
S1=1,S2=4,S3=9,S4=16,S5=25,…
The n-th square number is
Sn=n2=n⋅n
This is the simplest of all figurate-number formulas. Geometrically, Sn is the area of a square with integer side length n (counted in unit squares), or equivalently the number of unit lattice points in such a square.
Alternative characterization. Square numbers are the sums of consecutive odd numbers from 1:
11+31+3+51+3+5+7=1=S1=4=S2=9=S3=16=S4
In general, Sn=1+3+5+⋯+(2n−1), the sum of the first n odd numbers.
For deeper coverage see square number, perfect square, and figurate numbers.
The Closed Form and the Gnomon
Closed form.Sn=n2 — the simplest formula in the figurate family.
Geometric proof via gnomons. A gnomon is the L-shaped piece added to extend one square into the next. Going from an n by n square to an (n+1) by (n+1) square requires adding n dots along the right side, n dots along the bottom, and 1 corner dot — a total of 2n+1 dots, the (n+1)-th odd number.
Stacking gnomons one at a time gives:
Sn=k=1∑n(2k−1)
A classical proof that the sum of the first n odd numbers is n2.
Algebraic identity for the partial sum. The sum of the first n squares is
k=1∑nk2=6n(n+1)(2n+1)
This formula appears in calculus (Riemann sums approaching x3/3), in finance (running totals of squared error), and in basic number theory.
The Membership Test
Given a positive integer m, deciding whether it is a perfect square is straightforward.
The test.m is a square number if and only if m is a positive integer. Computationally: take the square root, round to the nearest integer s, and verify s2=m. If the equality holds, m=Ss. Otherwise m is not a perfect square.
Why rounding is needed. Floating-point square root is approximate. 169 might compute to 12.9999999… instead of exactly 13. Rounding before the verification step avoids missing valid squares.
Example. Is 169 a perfect square? Compute 169=13. Verify 132=169. Yes — 169=S13.
Non-example. Is 200 a perfect square? Compute 200≈14.14. Round to 14; verify 142=196=200. So 200 is not a perfect square. The nearest are S14=196 and S15=225.
Number-theoretic patterns. A perfect square never ends in 2, 3, 7, or 8 (in base 10). This gives a quick rejection filter before computing the square root, useful in mental arithmetic.
Properties and Identities
Square numbers have a rich set of identities — many of them appear in elementary algebra and number theory.
• Recurrence: Sn=Sn−1+(2n−1) with S1=1. Each square adds the next odd number. • Sum of two consecutive triangulars: Tn+Tn−1=n2=Sn. Two consecutive triangular numbers sum to a square. • Difference of consecutive squares: Sn+1−Sn=2n+1. Consecutive squares differ by consecutive odd numbers. • Difference of squares: a2−b2=(a−b)(a+b). The most-used factoring identity. • Sum of first $n$ squares: ∑k=1nk2=6n(n+1)(2n+1). Polynomial of degree 3 in n. • Sum of first $n$ cubes: ∑k=1nk3=Tn2=(2n(n+1))2. The sum of cubes is the square of the sum. • Lagrange's four-square theorem: every non-negative integer is a sum of at most four squares. The number of representations is given by Jacobi's formula. • Pythagorean triples: integer solutions to a2+b2=c2 — sums of two squares equal to a square. The smallest is 32+42=52.
• Area. A square with integer side n has area n2. The most direct geometric meaning. • Quadratic formulas. The discriminant b2−4ac is a difference of a square and a multiple. Real roots exist exactly when this is non-negative; rational roots require it to be a perfect square. • Distance formula. The squared distance between (x1,y1) and (x2,y2) is (x2−x1)2+(y2−y1)2, the sum of two squares. • Pythagorean theorem.a2+b2=c2 for a right triangle. Both classical and modern geometry rely on this. • Least squares. Statistical regression minimizes the sum of squared residuals. The squares come from quadratic loss; the minimum has a closed form involving sums of Sn. • Variance. Statistical variance is the average of squared deviations from the mean. Squared deviations weight outliers more than absolute deviations. • Inverse square laws. Gravity, electric force, light intensity, sound intensity — all decay as 1/r2 with distance. The square arises from spreading over a surface area proportional to r2. • Energy. Kinetic energy 21mv2 scales with the square of velocity. Doubling speed quadruples energy.
Square Numbers in Number Theory
Squares are central to many results in number theory. A few of the most important.
Lagrange's four-square theorem. Every non-negative integer is the sum of at most four perfect squares. Examples:
7=4+1+1+1,15=9+4+1+1,23=9+9+4+1
Three squares aren't enough: 7 cannot be written as the sum of three perfect squares. The characterization (Legendre's three-square theorem) excludes numbers of the form 4a(8b+7).
Fermat's two-square theorem. A prime p is the sum of two squares if and only if p=2 or p≡1(mod4). So 5=1+4, 13=4+9, 17=1+16, but 3, 7, 11, 19 are not.
Quadratic residues. A number a is a quadratic residue modulo p if a≡x2(modp) for some x. The structure of which numbers are residues is governed by quadratic reciprocity, one of Gauss's deepest results.
Pell equation.x2−Dy2=1 for non-square D. Solutions involve continued fractions and generate the square-triangular numbers and other figurate intersections.
Perfect squares in Pascal's triangle. Row sums and column sums produce squares in surprising places, including the identity ∑(kn)2=(n2n).
Common Mistakes
• Confusing square with square root.Sn=n2 means: input the index n, output its square. The inverse is the square root: input m, output n=m (if m is a perfect square). The membership test uses the square root; the lookup uses the square.
• Floating-point rounding errors in the membership test.169 might compute as 12.99999… in floating-point. Always round before verifying with s2=m. Languages with integer square root functions (like Python's isqrt) avoid this issue.
• Forgetting that 0 and 1 are special.02=0 and 12=1, so 0 and 1 are perfect squares by the usual definition. This explorer starts the sequence at S1=1, treating 0 as outside the sequence.
• Confusing square numbers with squared variables.Sn=n2 uses an integer index. The expression x2 for real or complex x is "the square of x" but only special values produce square numbers.
• Off-by-one when summing. The sum 1+4+9+⋯+n2 has n terms, equal to n(n+1)(2n+1)/6. The sum 1+4+9+⋯+N where N is itself a square (so N=n2) ends at the same place — just stated differently.
• Last-digit rejection over-eagerness. A number ending in 0, 1, 4, 5, 6, or 9 might be a perfect square — but only might. 11, 14, 19 are not. The last-digit test only rejects, never confirms.
Related Sequences and Concepts
Triangular Numbers — Tn=n(n+1)/2. The first figurate family. Tn+Tn−1=Sn connects them.
Pentagonal Numbers — Pn=n(3n−1)/2. The next polygonal sequence in the figurate family.
Hexagonal Numbers — Hn=n(2n−1). Every hexagonal number is also triangular.
Cubic Numbers — n3. The 3D analog of squares.
Perfect Square — the same concept as a square number, usually used in number-theoretic contexts. Every square number is a perfect square; the terms are interchangeable.
Square Triangular Numbers — numbers that are both square and triangular: 1, 36, 1225, 41616, ... Solutions to a Pell equation.
Pythagorean Triples — integer triples (a,b,c) with a2+b2=c2. The most famous Diophantine equation. Primitive triples are generated by a=m2−n2, b=2mn, c=m2+n2.
Sum of Squares — the function rk(n) counting representations of n as a sum of k squares. Studied extensively from Jacobi to modern modular-forms theory.
Quadratic Equation — ax2+bx+c=0. Square numbers arise in the discriminant and in completing the square.
Square Root — the inverse operation. Sn=n for integer n.
Quadratic Residue — modular arithmetic concept. a is a residue mod p if a≡x2(modp). Half of nonzero residues mod a prime are quadratic residues.
Variance and Standard Deviation — statistical measures involving squared deviations. The "least squares" approach to regression and the central limit theorem depend on the algebra of squares.