When you sell capital assets, which include just about any assets you use for personal or investment purposes like a house, car or stocks, you have to pay taxes on your capital gains. But your gains don't mean the sales price. Your capital gains are equal to your proceeds minus your basis. If your basis is greater than your proceeds, you have a capital loss.
When you buy and sell capital assets, such as stocks, you often pay a commission or transaction fee. The fees you pay increase your basis in the asset. For example, if you pay a $10 commission when you purchase stocks that would otherwise cost $1,700, your basis for the stock is $1,710. This means you'll have $10 less of capital gains when you sell because you can subtract transaction costs from your sales proceeds. Your taxable capital gain is only $190 -- not $200 -- if you sell the stock for $1,900.
Improvements Increase Basis
If you make improvements to a capital asset like a house, you can increase your basis by the cost of those improvements. For example, if you add on a garage for $20,000, you can add that amount to your basis. Maintenance expenses, such as fixing a leaky pipe or a crack in your driveway, don't count, however. Neither can you include the cost of any improvements you've later replaced. For example, if you replace all the carpet in the home and replace it again several years later, you can't count the first replacement cost as part of your basis, according to IRS Publication 523.
Offsetting with Capital Losses
You can offset capital gains with capital losses during the same year, or with capital losses you've carried forward from a prior year. For example, if you have $5,000 in capital gains but you sold another stock at a $1,000 loss, you only pay taxes on $4,000 of capital gains. You can't include capital losses from selling any personal use items, however. If you paid $250,000 when you bought your house and then sell it for $240,000, you can't use the $10,000 loss to offset other capital gains. (ref 1)