Deciding whether to put a comma before or after but in a sentence is hard for a lot of writers, but it doesn’t have to be for you!
When Do You Need a Comma Before But?
You should put a comma before but only when but is connecting two independent clauses.
How do you know you have two independent clauses? First, look at the words before but: I would go for a walk.