Theory:

The natural numbers are \(1\), \(2\), \(3\), \(4\), …
 
We need to find the value of \(1^2 + 2^2 + 3^2  + …. + n^2\).
 
Consider the identity \((x + 1)^{k + 1} - x^{k + 1}\).
 
Since the power of all the numbers are \(2\), put \(k = 2\) in the above identity.
 
\((x + 1)^{2 + 1} - x^{2 + 1} = (x + 1)^3 - x^3\)
 
\(= x^3 + 3x^2 + 3x + 1^3 - x^3\)
 
\(= 3x^2 + 3x + 1\)
 
\((x + 1)^3 - x^3 = 3x^2 + 3x + 1\) - - - - (I)
 
Now, substitute \(x = 1, 2, 3, … n\) in equation (I).
 
When \(x = 1\), \(2^3 - 1^3 = 3(1)^2 + 3(1) + 1\)
 
When \(x = 2\), \(3^3 - 2^3 = 3(2)^2 + 3(2) + 1\)
 
When \(x = 3\), \(4^3 - 3^3 = 3(3)^2 + 3(3) + 1\)
 
           \(\vdots\)             \(\vdots\)             \(\vdots\)
 
When \(x = n - 1\), \(n^3 - (n - 1)^3 = 3(n - 1)^2 + 3(n - 1) + 1\)
 
When \(x = n\), \((n + 1)^3 - n^3 = 3(n)^2 + 3(n) + 1\)
 
Add all the above equations of \(x\) values.
 
\(2^3 - 1^3 + 3^3 - 2^3 + 4^3 - 3^3  + \cdots + n^3 - (n - 1)^3 + (n + 1)^3 - n^3 = 3(1)^2 + 3(1) + 1 + 3(2)^2 + 3(2) + 1 + 3(3)^2 + 3(3) + 1 + \cdots + 3(n - 1)^2 + 3(n - 1) + 1 + 3(n)^2 + 3(n) + 1\)
 
\(2^3 + 3^3 + 4^3 + \cdots + n^3 + (n + 1)^3 - (1^3 + 2^3 + 3^3 + \cdots + (n - 1)^3 + n^3) = 3(1^2 + 2^2 + 3^2 + \cdots + (n - 1)^2 + n^2) + 3(1 + 2 + 3 + \cdots (n - 1) + n) + (1 + 1 + 1 + ... n \ times )\)
 
Cancelling the same terms with opposite signs on LHS, we get:
 
\((n + 1)^3 - 1^3 = 3(1^2 + 2^2 + 3^2 + … (n - 1)^2 + n^2) + 3(1 + 2 + 3 + … (n - 1) + n) + n\)
 
\(n^3 + 3n^2 + 3n + 1^3 - 1^3 = 3(1^2 + 2^2 + 3^2 + … (n - 1)^2 + n^2) + 3(1 + 2 + 3 + … (n - 1) + n) + n\)
 
\(n^3 + 3n^2 + 3n = 3(1^2 + 2^2 + 3^2 + … (n - 1)^2 + n^2) + 3(1 + 2 + 3 + … (n - 1) + n) + n\)
 
Apply sum of first \(n\) terms of natural numbers formula in \(1 + 2 + 3 + .. (n - 1) + n\).
 
n3+3n2+3n=3(12+22+32+...(n1)2+n2)+3n(n+1)2+n
 
n3+3n2+3n3n(n+1)2n=3(12+22+32+...(n1)2+n2)
 
2n3+6n2+6n3n23n2n2=3(12+22+32+...(n1)2+n2)
 
2n3+3n2+n2=3(12+22+32+...(n1)2+n2)
 
n(2n2+3n+1)2=3(12+22+32+...(n1)2+n2)
 
n(2n2+2n+n+1)2×3=12+22+32+...(n1)2+n2
 
n(2n(n+1)+1(n+1))6=12+22+32+...(n1)2+n2
 
n(n+1)(2n+1)6=12+22+32+...(n1)2+n2
 
Therefore, 12+22+32+...(n1)2+n2=n(n+1)(2n+1)6
Sum of squares of first \(n\) natural numbers \(=\) n(n+1)(2n+1)6