Basically, seeded throughout season 3 is the possibility that the Doctor is not the only survivor of the Time War, and also a mysterious individual called Harold Saxon is shadowing the Doctor and Martha. In season 3's Utopia, the Doctor-now with Captain Jack also in tow-journey to an era near the end of the universe, where the last remnants of humankind are trying to get a spaceship to go to a place called "Utopia", with the help of a kindly old scientist, Yana (Derek Jacobi). However, Martha discovers that Yana has a "Chameleon Arch"-a watch-like device that turns Time Lords into humans, and also stores their memories-The Doctor used it to escape from bad guys in an earlier story. Martha noticing the watch causes Yana to notice it too. He opens it, restoring his time lord biology and memories, and he becomes his former identity-The Master, who the Doctor presumed dead like the other Time Lords, but who actually survived by hiding from the Daleks using the arch.
After showing how evil he now is by killing his long time assistant, she shoots him, which triggers a regeneration into a younger form (John Simm). The new Master steals the TARDIS, and using his hypnotic powers and other deceptions, eventually becomes prime minister "Harold Saxon", and capturing the Doctor, Martha, Jack, and Martha's family, and with the help of the "Toclofane" (The humans from the future who have devolved and been placed in sphere war machines almost like Daleks) pretty much decimates humanity and uses it to turn earth into a war machine against the rest of the universe. The Doctor and co. of course stop him (After a year spent under his control), and actually reverse the changes he brought to Earth. However, the Master is then shot by his 'wife' Lucy. The Doctor cremates his body but part of him-a ring-survives.
Later in "The End Of Time" the ring is revealed to have his essence (Sort of like the Chameleon arch), and using Lucy some followers of him ressurect him in his "Saxon" body. However, the ressurection doesn't turn out as planned, and the Master becomes an even more insane, ravenous and destitute version of himself. He also gains the ability to shoot lightning, and his skin ocassionally has an 'x-ray' effect. However he eventually gets some alien technology-due to a sort of misplaced trust by a wealthy benefactor who believes he can use the Master's genius-and eventually uses it to turn all humans into dopellgangers of himself (Seriously). Without going into too much detail and technobabble, this sort of helps bring back the Time Lords (Before the events of "Day"). The Doctor decides though to sever the link between the Master and the Time Lords, which causes the Time Lords/Gallifrey to return to a sort of "Time locked" state. The Master goes with them, blaming them for the sound of drums thing and his whole evilness thing.
At this point it's unclear how the Master/Mistress escaped from the Time lock/other dimension/whatever Gallifrey escaped from, and how he became "Missy", especially since his/her last body appeared to be dying and possibly incapable of regeneration. Although promo material from season 9 might imply it had something to do with the Sisterhood of Karn seen in "Night of the Doctor" (and also in the classic story Brain of Morbius).