Margin and markup are not the same number
Both describe the same profit on the same trade. Margin measures it against what you sold for; markup measures it against what you paid. Buy at forty and sell at eighty and the profit is forty either way, but the margin is fifty per cent and the markup is a hundred.
The confusion is expensive in one direction in particular. A shop told to work on a forty per cent margin, that instead adds forty per cent to cost, sells at a margin of about twenty-nine per cent and wonders where the money went. Going the other way it overprices and loses the sale. This page prints both figures for every trade, always, so the two can never be quietly swapped.
Two rules of thumb worth keeping: markup is never the smaller number of the two, and margin stays below a hundred per cent, because reaching it would mean the goods cost nothing. The two are equal only when there is no profit at all, and a margin prints as a round hundred only when the cost is so small beside the price that it rounds away.
Three directions, one trade
You can start from a cost and a selling price, from a cost and the margin you need, or from a cost and the markup you want to apply. All three describe the same three quantities, and whichever two you have, the page works out the rest.
Pricing from a margin is the direction most people want and the one most calculators leave out. It is a division rather than a multiplication: a cost divided by one minus the margin. Adding the margin to the cost is the mistake that produces the wrong answer above.
Rounding, and why the margin can read back slightly differently
A price is money and money has a smallest unit. Asking for a particular margin gives a price that has to be rounded to that unit, and the margin of the rounded price is not exactly the margin asked for. On ordinary amounts the difference is invisible. On very small ones it is not: a cost of one, priced for a five per cent margin, rounds to 1.05, whose actual margin is a little under 4.8 per cent.
The page always prints the margin of the price it actually produced, rather than echoing back the figure typed in. A calculator that showed you the number you asked for would be telling you about your question rather than about the answer.
What the trade does not include
The cost here is whatever you decide to count as cost, and that decision is the whole of cost accounting. Landed cost with shipping and duty, cost plus a share of overhead, or the invoice price alone all give different margins on the same sale. Pick one, use it consistently, and know which one you picked.
Not in the arithmetic at all: sales tax, which is collected on behalf of a government and is not revenue; card fees and marketplace commissions, which come out of the money you receive; returns; and the discounts a customer actually takes, which the discount calculator handles.