The Master and the Doctor can be said to be enemies, but it may be more correct to say that they're adversaries. They don't really hate each other, but they have different ideas of what they want for the universe and for themselves. Also, the Master has had a very troubled life and the Doctor has caused some trouble for him.
In multiple instances both the Master and the Doctor have had chances to kill each other, but chose not to. This may be not only because of their past friendship, but because they are the last of their kind (though currently, so far as we know, the Master is now gone) and do not wish to be alone.
From TV, we don't get that much background, but we know that they knew each other when they were much younger back on Gallifrey, and used to be friends. At some point, the Master 'went mad' or 'turned evil', and since then the Doctor has been stopping him whenever he goes too far.
If you read the novels or listen to the audio stories (and accept them as canon), you'll get a lot more background, but the answer is basically the same—it's still nuanced and complicated, and different at different times in their lives. See, for example, "Divided Loyalties" (novel), "The Adventuress of Henrietta Street" (novel), and "The Gallifrey Chronicles" (novel).