Profit margin is the profit divided by the selling price, written as a percentage: (price − cost) ÷ price × 100.
TL;DR: Margin = (price − cost) ÷ price × 100. A $200 price on a $150 cost is a 25% margin. The margin calculator works it out from any two of cost, price, or profit.
The formula with a worked example
Take an item that costs you $150 and sells for $200. The profit is $50. Divide that by the $200 price and you get 0.25, or 25%. So a quarter of every sale is profit, and three quarters covers the cost.
Note that you divide by the price, not the cost. Dividing $50 by the $150 cost would give 33.3%, which is the markup, a different figure. Enter the cost and price into the margin calculator and it returns the margin without you having to remember which number goes on the bottom.
Margin versus markup
Both start from the same $50 profit, but they answer different questions. Margin asks what share of the sale is profit. Markup asks how much you added on top of cost. On this $150/$200 item the margin is 25% and the markup is 33.3%. They describe one sale, just from two angles.
Gross margin versus net margin
Gross margin uses only the direct cost of the product, the $150 above. Net margin goes further and subtracts everything else: rent, wages, shipping, tax, and other overheads. A shop with a 40% gross margin might end up with a 6% net margin once the bills are paid. Gross margin tells you whether the product itself earns money; net margin tells you whether the business does.