When a coil spring is compressed, the work is done on the spring. The elastic potential energy :
Work done by a coil spring is given by,
Where k is the spring constant/stiffness
X is the extension or compression produced
This work done is stored in spring as elastic potential energy (PE) when the spring is compressed and hence elastic potential energy decreases.