Margarine was developed to be a substitute for butter and is typically made from plant-based oils such as soybean, palm, canola, etc. The main difference between butter (from cows or goats) and margarine is that margarine has trans fats and butter has saturated fats which are known for raising cholesterol a little more than the trans.
When it comes to baking, however, butter always trumps margarine. Whether you’re making cakes, cookies, pastries, etc. the butter provides a richer flavor. Whereas margarine typically contains more water and less fat and will make your cookies and pastries spread out thinner and perhaps even burn.