After fusing helium in its core to carbon, the Sun will begin to collapse again, evolving into a compact white dwarf star after ejecting its outer atmosphere as a planetary nebula. In 50 billion years, if the Earth and Moon are not engulfed by the Sun, they will become tidelocked, with each showing only one face to the other. Thereafter, the tidal action of the Sun will extract angular momentum from the system, causing the lunar orbit to decay and the Earth's spin to accelerate.
Over time intervals of around 30 trillion years, the Sun will undergo a close encounter with another star. As a consequence, the orbits of their planets can become disrupted, potentially ejecting them from the system entirely. If Earth is not destroyed by the expanding red giant Sun in 7.6 billion years and not ejected from its orbit by a stellar encounter, its ultimate fate will be that it collides with the black dwarf Sun due to the decay of its orbit via gravitational radiation, in 100 quintillion years.
Explanation from: https://en.wikipedia.org/wiki/Future_of_Earth#Solar_evolution