We describe a magnetic spring consisting of two magnetic rings with different dimensions, located concentrically in the same direction of magnetization. One of the two magnetic rings is fixed and the other can move axially. Because of the magnetic field, the two magnetic rings tend to keep away from each other at a fixed axial distance. If the relative positions of the two magnetic rings are changed, a restoring force, namely, an elastic force, is produced. This antipull/antipush phenomenon is quite similar to the elastic force in a metal spring. Our measurements demonstrate that the relation of elasticity and the displacement is quite linear and the elastic force is about 100 times the weight of the magnetic rings. The magnetic spring can also be used as a magnetic bearing, if one magnetic ring is fixed and the other rotates. We describe a magnetic spring train and magnetic bearing kilowatt-hour meter as examples of applications.