How do you calculate the yield to maturity (YTM) of a bond?

How do you calculate the yield to maturity (YTM) of a bond, and why is it important?,