The YTM is The weighted average of each spot rate at different maturities. The spot rate is a single rate used to discount a coupon payment for a determined maturity and the yield to maturity is the rate that makes future cash flows equal to the bond market price
Suppose that the 1-year spot rate is 1%. This means that a payment of, say, $100 one year from today will have a present value of $100 / 1.011 = $99.0099.
Suppose that the 2-year spot rate is 2%. This means that a payment of, say, $100 two years from today will have a present value of $100 / 1.022 = $96.1169.
Suppose that the 3-year spot rate is 2.5%. This means that a payment of, say, $100 three years from today will have a present value of $100 / 1.0253 = $92.8599.
A 3-year, annual pay, 6% coupon, $1,000 par bond will have a value today of:
by weighted average I mean, that the YTM is going to be closer to the spot rate where you discount the most of the cash flow (ex. Principal), if the bond is a 3 year bond and the spots are 3%, 4% and 5% and the bond is bullet payment, the YTM is going to be between 3% and 5%, but closer to 5% cause the weight of the principal payment