When you stretch a spring you do work on it. The energy transferred is stored in the spring as elastic potential energy. If the spring is not stretched beyond its limit, all of this energy is stored and can be released when the spring returns to its original length.
For a spring that obeys F = k × x, the energy transferred in stretching is given by:
energy transferred = 0.5 × spring constant × extension2
E = ½ × k × x2
Energy E is in joules (J), k is in N/m and x is in metres (m).
Worked example: a spring has k = 40 N/m and is stretched by 0.10 m. Then x2 = 0.10 × 0.10 = 0.01, so E = 0.5 × 40 × 0.01 = 0.2 J. Remember to square the extension first, and then multiply.
Because the extension is squared, doubling the extension makes the stored energy four times bigger. Another example: k = 200 N/m and x = 0.05 m gives E = 0.5 × 200 × 0.0025 = 0.25 J.