It depends on the context in which "but" is being used.

If "but" is used to join two independent clauses (i.e., two complete sentences), then a comma is usually placed before "but." For example: "I wanted to go to the party, but I had to study for my exams."

However, if "but" is used to join two words, phrases, or dependent clauses, then a comma is not necessary. For example: "I like ice cream but not cake."

It's important to note that there are some exceptions and nuances to these rules, and the use of a comma can depend on the specific style guide being followed.