In Numbers 31, the Jews wipe out Midyan. I'd think this referred to only those of Midyan who happened to be defending against the Jews' attack, and not the whole nation, except that even women and boys were killed, who presumably don't go to war. So, seemingly, all of Midyan (except the girls mentioned in verse 18) was wiped out. Yet, we see Midyan fighting again in Judges 6. What gives?
In Maayan Beis Hashoeivah 31 7, Rabbi Shwab asks this very question and suggests that perhaps Midyan was a tremendous nation or perhaps two nations, and only the ones under the jurisdiction of the five kings living on the border of Moav were killed, leaving the Moavites near Egypt alive. He also answers with this idea how Pinchas would wage war against his mother's kinsmen. Answer is his mother was from the other Moav.