What HpRyder said.
An example I found:
"You have to allocate the capital gain between the rental use and
personal use. Only the capital gain due to personal use is tax-free
(unless it is more than 500k).
Say you bought the house for $100,000. 10 years depreciation would be
about $36,300. You sell it in 2012 for $1,000,000. So 2 years
qualified use, 10 non-qualifed. So of the 900k capital gain, 2/12 or
$150,000 is qualified. 750,000 is not qualified. You have to
recapture your depreciation, so at the end must pay capital gain on
$786,300. At least that's how I think the example is".