Investors & landlords

The easy-to-read version is on page 11 of Publication 551 (but things are more complicated in situations where there is NEITHER a gain or a loss):

 

 

Sale of property.

 

If you later sell or dispose of property changed to business or rental use, the basis of the property you use will depend on whether you're figuring gain or loss.

Gain. 

The basis for figuring a gain is your adjusted basis when you sell the property.

Example. 

Assume the same facts as in the previous example except that you sell the property at a gain after being allowed depreciation deductions of $37,500. Your adjusted basis for figuring gain is $165,500 ($178,000 + $25,000 (land) − $37,500).

Loss. 

Figure the basis for a loss starting with the smaller of your adjusted basis or the FMV of the property at the time of the change to business or rental use. Then adjust this amount for the period after the change in the property's use, as discussed earlier under Adjusted Basis , to arrive at a basis for loss.

Example. 

Assume the same facts as in the previous example, except that you sell the property at a loss after being allowed depreciation deductions of $37,500. In this case, you would start with the FMV on the date of the change to rental use ($180,000) because it's less than the adjusted basis of $203,000 ($178,000 + $25,000) on that date. Reduce that amount ($180,000) by the depreciation deductions to arrive at a basis for loss of $142,500 ($180,000 − $37,500).

 

https://www.irs.gov/pub/irs-pdf/p551.pdf#page=11