To calculate margin, subtract the cost of goods sold (COGS) from the sales price (revenue), then divide the result by the revenue and multiply by 100 to get a percentage.