Only works when using the proceeds to acquire another rental. It's considered by the IRS as a Like-Kind exchange, so as you are exchanging properties(selling one and using proceeds to acquire 2nd) the gains(if any) are taxed but the exchanged portion is not. Using it to pay down an existing mortgage does not qualify because it is not an exchange of funds, it would be pure gains.