A gain on retirement of bonds occurs when a bond issuer buys back bonds for less than the amount of the associated liability. The liability is the carrying amount of the bonds; this is the face value of the bonds , minus any unamortized discount (or plus any unamortized premium), minus any unamortized bond issuance cost.
For example, a company issued $100,000 of bonds five years ago at a premium of $5,000. The unamortized balance of the premium is now $4,000. The carrying amount of the bond is therefore $104,000. The company buys the bonds back for $102,000. The difference between the repurchase price and the carrying amount is $2,000, which is the gain the company can recognize on the retirement of bonds.