Difference of two squares
By the commutative law, the middle two terms cancel:
The resulting identity is one of the most commonly used in mathematics. Among many uses, it gives a simple proof of the AM–GM inequality in two variables.
The proof holds in any commutative ring.
Conversely, if this identity holds in a ring R for all pairs of elements a and b, then R is commutative. To see this, apply the distributive law to the right-hand side of the equation and get
For this to be equal to , we must have
for all pairs a, b, so R is commutative.
The difference of two squares can also be illustrated geometrically as the difference of two square areas in a plane. In the diagram, the shaded part represents the difference between the areas of the two squares, i.e. . The area of the shaded part can be found by adding the areas of the two rectangles; , which can be factorized to . Therefore, .
Another geometric proof proceeds as follows: We start with the figure shown in the first diagram below, a large square with a smaller square removed from it. The side of the entire square is a, and the side of the small removed square is b. The area of the shaded region is . A cut is made, splitting the region into two rectangular pieces, as shown in the second diagram. The larger piece, at the top, has width a and height a-b. The smaller piece, at the bottom, has width a-b and height b. Now the smaller piece can be detached, rotated, and placed to the right of the larger piece. In this new arrangement, shown in the last diagram below, the two pieces together form a rectangle, whose width is and whose height is . This rectangle's area is . Since this rectangle came from rearranging the original figure, it must have the same area as the original figure. Therefore, .
Factorization of polynomials and simplification of expressions
The formula for the difference of two squares can be used for factoring polynomials that contain the square of a first quantity minus the square of a second quantity. For example, the polynomial can be factored as follows:
As a second example, the first two terms of can be factored as , so we have:
Moreover, this formula can also be used for simplifying expressions:
Complex number case: sum of two squares
For example, the complex roots of can be found using difference of two squares:
- (since )
Therefore, the linear factors are and .
Since the two factors found by this method are complex conjugates, we can use this in reverse as a method of multiplying a complex number to get a real number. This is used to get real denominators in complex fractions.
The difference of two squares can also be used in the rationalising of irrational denominators. This is a method for removing surds from expressions (or at least moving them), applying to division by some combinations involving square roots.
For example: The denominator of can be rationalised as follows:
Here, the irrational denominator has been rationalised to .
The difference of two squares can also be used as an arithmetical short cut. If two numbers (whose average is a number which is easily squared) are multiplied, the difference of two squares can be used to give you the product of the original two numbers.
Using the difference of two squares, can be restated as
- which is .
Difference of two consecutive perfect squares
Therefore, the difference of two consecutive perfect squares is an odd number. Similarly, the difference of two arbitrary perfect squares is calculated as follows:
Therefore, the difference of two even perfect squares is a multiple of 4 and the difference of two odd perfect squares is a multiple of 8.
Factorization of integers
Several algorithms in number theory and cryptography use differences of squares to find factors of integers and detect composite numbers. A simple example is the Fermat factorization method, which considers the sequence of numbers , for . If one of the equals a perfect square , then is a (potentially non-trivial) factorization of .
This trick can be generalized as follows. If mod and mod , then is composite with non-trivial factors and . This forms the basis of several factorization algorithms (such as the quadratic sieve) and can be combined with the Fermat primality test to give the stronger Miller–Rabin primality test.
The proof is identical. By the way, assuming that a and b have equal norms (which means that their dot squares are equal), it demonstrates analytically the fact that two diagonals of a rhombus are perpendicular. This follows from the left side of the equation being equal to zero, requiring the right side to equal zero as well, and so the vector sum of a + b (the long diagonal of the rhombus) dotted with the vector difference a - b (the short diagonal of the rhombus) must equal zero, which indicates the diagonals are perpendicular.
Difference of two nth powers
If a and b are two elements of a commutative ring R, then .
Historically, the Babylonians used the difference of two squares to calculate multiplications. 
93 x 87 = 90² - 3² = 8091
64 x 56 = 60² - 4² = 3584
- Congruum, the shared difference of three squares in arithmetic progression
- Conjugate (algebra)
- Complex or imaginary numbers TheMathPage.com, retrieved 22 December 2011
- Multiplying Radicals TheMathPage.com, retrieved 22 December 2011
- Stanton, James Stuart (2005). Encyclopedia of Mathematics. Infobase Publishing. p. 131. ISBN 0-8160-5124-0.
- Tussy, Alan S.; Gustafson, Roy David (2011). Elementary Algebra (5th ed.). Cengage Learning. pp. 467–469. ISBN 978-1-111-56766-8.
- difference of two squares at mathpages.com