How does a firm calculate marginal cost?

A. By adding up its variable costs and fixed costs
B. By dividing the change in output by the change in total cost
C. By subtracting the total cost from total revenue
D. By dividing the change in total cost by the change in output

D. By dividing the change in total cost by the change in output