A body moving to and fro around a mean position in which its acceleration is directly proportional to its displacement and directed towards the mean position is said to be in simple harmonic motion (SHM), a type of periodic motion.
The behaviour of energy during motion is one of the most interesting parts of SHM. Although SHM conserves total mechanical energy, it continuously changes between two forms: potential energy (P.E.) and kinetic energy (K.E.).

Energy in Simple Harmonic Motion (SHM)
We think a mass on a frictionless surface that is fastened to a spring. It begins to oscillate back and forth when the mass is pulled and released. This is a quintessential SHM example.
Following is a description of the energy are in this motion:
Potential Energy (P.E.) in SHM
In SHM, potential energy is stored as a result of an object’s displacement from its mean position. The spring’s compression or stretching provides the potential energy for a spring-mass system.
The formula for potential energy at any displacement x is:
P.E. = 1 / 2kx2
Where:
k is the spring constant
x is the displacement from the mean position
At the mean position (x = 0), potential energy is zero. At the extreme positions (x = ±A), potential energy is maximum.
2. Kinetic Energy (K.E.) in SHM
Kinetic energy is the energy of motion. When the mass is moving, it has kinetic energy.
The formula for kinetic energy is:
K.E. = 1 / 2mv2
In SHM, velocity changes with position, so kinetic energy also changes. Using SHM equations, we can also write:
K.E. = 1 / 2k (A2−x2)
This means:
At the mean position (x = 0), kinetic energy is maximum.
At the extreme positions (x = ±A), kinetic energy is zero because the velocity is zero there.
3. Total Mechanical Energy in SHM
The total energy (E) is the sum of kinetic and potential energy:
E = K.E. + P.E.
Let’s plug in the equations:
E = 1 / 2kx2 + 1 / 2k(A2−x2) = 1 / 2kA2
So, total energy in SHM is constant and equal to:
E = 1 / 2kA2
Even though it continuously alternates between kinetic and potential energy when in motion, this total energy remains constant over time.
Energy Transformation in SHM
As the mass oscillates:
At the mean position: K.E. is maximum, P.E. is zero
At any intermediate position: Both K.E. and P.E. are present
At the extreme positions: P.E. is maximum, K.E. is zero
As long as there is no friction or energy loss, the motion is sustained by this ongoing interchange of kinetic and potential energy.

Key Points to Remember
Energy in SHM is always conserved.
Total mechanical energy E = 1 / 2kA2
K.E. is maximum at the mean position, zero at extremes.
P.E. is zero at the mean position, maximum at extremes.
The total energy graph is constant; the K.E. and P.E. graphs are sinusoidal and complementary.
Summary
We can better understand how nature balances forces and motion when we understand energy in SHM. The overall energy of the object stays constant despite its constant changes in position and speed; it only changes between kinetic and potential forms. In addition to being striking, this idea serves as the basis for a subsequent understanding of waves, oscillations, and even quantum physics.
In SHM, the two main forms of energy are Kinetic Energy (K.E.) and Potential Energy (P.E.). The total mechanical energy is the sum of these two and remains constant throughout the motion.
Potential energy at any displacement x from the mean position is given by:
P.E. = 1 / 2kx2
Where k is the spring constant and x is the displacement.
The total mechanical energy in SHM is:
E = 1 / 2kA2
Where A is the amplitude of motion. This energy remains constant.
Kinetic energy is maximum at the mean position (x = 0) because the velocity of the particle is greatest at that point.