When a vibrating body moves outwards, it increases pressure on the molecules of the medium surrounding it, for example, air and causes them to come close to each other. This is known as compression. When the vibrating body moves inwards, the pressure on the molecules gets reduced. So, the gaps between the molecules increase causing them to spread out. This is known as rarefaction.