The exclusion is on your principal residence. You must have lived in it for at least 2 out of the last 5 years.
Compare the cost of the home plus the large improvements you made with the sales price, less the costs to sell the home. This is your gain or loss.
Unfortunately, the loss would not be deductible.
But the gain may not have to be included in income.
You may qualify to exclude up to $250,000 of the gain from your income, or $500,000 if filing Married Filing Joint.
You must meet the ownership and the use tests. In order to meet the ownership test you must have owned the home for at least 2 years and you must have lived in it for at least 2 years. You must have used your house as your main house for a period of at least 2 years out of the 5 years before the sale of the home. Also, you can’t have excluded the gain on another home in the 2 years prior to this sale. That being said, if you have owned or lived in the house less than two years you may be able to pro-rate the exclusion using a work, health, or unforeseen event exception. For example, if you qualify for an exception (they are very broad) and you lived in the home for 12 out of 24 months, then had to move, your exclusion would be $250,000 of gain if you are married filing joint. ($500,000 x 12/24 = $250,000).
If you own more than one home, your principal residence is the one you lived in the most.