ownership period = 6+10+2 = 18 years
non-use period = 10 years.
The non-qualified gain is (total gain x 10/18).
and for primary residence portion total gain x 8/18, 500K can be excluded from it.
So your taxable gain = total gain x 10/18 (if total gain x 8/18 < 500K)
or total gain x 10/18 + (total gain x 8/18 - 500K)