The direct cost margin is calculated by taking the difference between the revenue generated by the sale of goods or services and the sum of all direct costs associated with the production of those goods, divided by the total revenue.