Most bonds pay interest in a lump sum twice per year. For example, a $10,000 face value bond paying a 5.0% coupon with semi-annual payments, will produce two interest payments per year of $250. The holder of the bonds at the specified payment date is paid the full coupon amount (in this example $250), regardless of when the bond was purchased.
To get the coupon payment, you might expect the price of the bond to rise by $250 before the specified date, and fall by the same amount right afterwards. (This process actually happens with stocks that pay large dividends.) As you can imagine, this would create a tremendous amount of price volatility without any underlying changes in market conditions or the bonds fundamental characteristics. To eliminate this unnecessary volatility, the concept of accrued interest is applied.
Bondholders get credit for the amount of time they hold a bond, meaning interest accrues between coupon payments on a pro rata basis. In the example above, the bond pays interest semi-annually. Assuming that the bond is sold 2 months after the last coupon payment, the seller would get 2 months of the 6 months worth of interest, at the time of sale (which is ⅓ of $250 coupon payment from our example). However, the accrued interest is not paid by the issuer, but by the buyer of bond. While the new buyer receives the entire coupon payment paid by the issuer, the buyer must pay the seller for the interest that has accrued since the last coupon payment.
So, why does a bond almost always cost more than the quoted price? Because when a bound is sold, the seller must pay the market price + accrued interest.
Typically, accrued interest is calculated using the following formula.
Accrued Interest = Face Value Of The Bonds x Coupon Rate x Factor
Coupon = Annual Interest Rate / Number of Payments
Factor = Time Held After The Last Coupon Payment / Time Between Coupon Payments
(In the example above, the factor was calculated at ⅓).
Typically, the amount of time is calculated assuming a month has 30 days, and a year has 360 days. This is known as the 30 / 360 day count method. As a consequence, you would actually get paid 30 days of interest in February even though the month has less than 30 days.