PE = kx²/2.
The force F to extend (or compress) a spring is proportional to the length of extension (or compression) x of the spring, i.e., it is a linear relationship. If the proportionality constant is k, then F= kx. The potential stored in the spring is the the done in stretching the spring. This is the average force kx/2 times the distance stretched x, which gives you ∆PE = kx²/2.