Examples:
* No comma: I like to eat ice cream, but I don't like chocolate.
* Comma: I like to eat ice cream, but, unfortunately, I'm lactose intolerant.
In the second example, the phrase "unfortunately" is parenthetical, meaning it could be removed without changing the meaning of the sentence. This is why a comma is used before and after it.
Here's a rule of thumb: If you can remove the phrase after "but" and the sentence still makes sense, then you probably need a comma. If not, then you don't.