Patrick McKeague has an excellent video explaining the math behind the golden rectangle. It also explains how to derive the formula for the golden ratio.
First we start with a square like so:
Mark halfway between one of the sides and draw a line from this point to one of the opposite corners. This forms a right triangle.
Now if you were to swing the hypotenuse of this right triangle down to zero degrees of the side of the origin (maintaining the same point of origin) and extend the square to the termination of this line you would get a golden rectangle.
The golden ratio would be the length of this rectangle divided it’s width . We know the width is 2. The length is made up of half of the side of the original square which is 1, plus the hypotenuse of the triangle that was formed above. Using the Pythagorean Theorem (a² + b² = c²) we see that the hypotenuse is:
1² + 2² = c²
1 + 4 = c²
c² = 5
√c² = √5
c = √5
So the length is 1 + √5. We can then see that the formula for the golden ration is:
1 + √5
—————— = φ
2
Now the cool thing is if you create a square of any size and follow the above procedure, you will always be able to reduce the equation down to the one above.