When you bake is there a difference between using butter and using margarine.

Yes, there is.

Most recipes call for unsalted butter. Margarine has salt so if you plan to use margarine you should remove 1/4 teaspoon salt from the recipe or just eliminate it entirely.

Another thing to remember is that butter will get hard fairly quickly so if you are making cookie dough that needs to be chilled you can stick it in the freezer for quicker chilling only if you plan to use margarine and NOT butter.
If you use butter, the butter will cause the dough to be too solid to shape. It won’t be frozen solid but it will not shape or roll without it being allowed to soften. And that kinda negates the whole chilling for easier rolling.

Cookies made with butter will have a crispier outside than cookies made with margarine.

Butter will melt at a lower temperature than margarine so cookies may spread more when using butter.

One thing to remember is that butter contains 80% fat and the amount in margarine can range from 100% fat to less than 50%.
Having a higher fat content is important when baking. So try not to use low fat margarine or tub margarine.

But, when making candy, you should always use real butter for the best quality. That is due to the fat content.

I always use butter over margarine when cooking. I also use cooking oil and shortening.

But when it comes done to it, it is whatever you prefer to use.

Just remember that one is not exactly the same as the other.