What is the purpose of an underlayment?

Flooring underlayment (also called underpad) is a thin material that rests between the floor covering and the subfloor. It smooths the surface to allow for easier installation and a better surface for the floor covering than the rigid subfloor, but it also serves to "soundproof" the footsteps, to soften the feeling of the flooring underfoot. Often it is used to improve adhesion, to provide better stability and it can also act as a moisture barrier. 

Soft underlayment can be foam or cork.*** These underlayments usually not attached to the subfloor, they are just "floating".  Foam and cork underpads provide a very slight buffer between the top floor covering and imperfections in the underlying subfloor and they can smooth out imperfections.

They can also be a good solution when you are installing a new floor covering directly over an old floor that is still in good shape. (For example, a layer of foam or cork can work well as an underlayment when you are installing laminate flooring over an existing hardwood or ceramic tile flooring.) 
***Please note that some vinyl and laminate flooring come with an attached underpad and there is no need to purchase underlayment separately.