The work you do compressing or stretching the spring must go into the energy stored in the spring. That energy is called elastic potential energy and is equal to the force, F, times the distance, s:
Elastic potential energy is Potential energy stored as a result of deformation of an elastic object, such as the stretching of a spring. It is equal to the work done to stretch the spring, which depends upon the spring constant k as well as the distance stretched.Now see the formulaes to calculate the potential energy is as follows:-
Spring Potential Energy:
U = ½ kx2 
Spring Force Constant:
k = 2u / x2 
Spring Stretch Length:
x = √(2U/k) 
U = Spring Potential Energy,
k = Spring Force Constant,
x = Spring Stretch Length.
I hope u got what u want !
Plz mark as the best!