Energy of a Mass on a Spring
In this movie, you see a mass hanging from a spring. The mass begins with only gravitational potential energy (GPE) since it is not moving and the spring is unstretched. As the mass falls, GPE is turned into kinetic energy (KE) which is present because the mass is now moving. The falling mass also does work on stretching the spring, so GPE also is turned into elastic potential energy (EPE). During the fall, the sum (total) of the GPE, KE, and EPE is equal to the initial GPE.
As the mass is brought to rest by the spring notice that the only type of energy remaining is EPE and it is equal to the original amount of GPE. The energy exchange is reversed as the spring does work on raising the ball to its original height.
This simulation is assuming that there is no air friction and no heating up of the spring as it bends.