Push down on a spring with your hand. The first centimetre is easy, the next is harder, and the next harder still, because a spring pushes back with a force proportional to how far it is squeezed: F=kx. The energy you put in is the work done against this growing force. On a graph of force against compression, that work is the area of a triangle with base x and height kx, which is 21kx2.
Two numbers set the stored energy. The spring constant k, in N/m, says how stiff the spring is: the spring in a ballpoint pen has a small k, while a car's suspension spring has a k in the tens of thousands of N/m. The deformation x, in metres, is how far the spring is stretched or squeezed from its natural length, not its total length. Because x is squared, a spring squeezed 4 cm stores four times the energy of the same spring squeezed 2 cm.
Not every stretched object obeys 21kx2. The formula rests on Hooke's law, which holds for springs and many materials only for small deformations. Stretch a spring too far and it bends permanently and will not spring back, so not all the energy you put in can be recovered. A rubber band follows Hooke's law only roughly. When a problem gives a force-stretch graph that is not a straight line, find the energy from the area under the graph instead.
Think of it like this. Drawing a bow shows the pattern: the farther back you pull, the harder the string pulls against your fingers, so each extra centimetre adds more energy than the one before. Draw it twice as far and it stores about four times the energy. A real bow only roughly follows Hooke's law; an ideal spring follows 21kx2 exactly.
Core idea. A spring stretched or compressed by x from its natural length stores 21kx2 of energy, the area under its force-stretch line, so the stored energy grows with the square of the deformation.