To what extent do transportation costs depend on the amount shipped, and how does infrastructure investment shape these costs? We model railroads as multiproduct firms and estimate the link between capacity utilization and costs using firm choices, the network structure of production, and publicly available routing data. We find a U-shaped relationship between marginal costs and rail utilization: As utilization increases, costs decrease by 30% to a low point at 55% utilization, before increasing by another 30%. Increased congestion in the rail network can explain a third of the 50% increase in real rail prices observed since 2004. We use our framework to study two normative and one positive policy questions: First, we estimate the network externalities of rail infrastructure investment, finding that investment in Arizona provides the highest returns, but only 3% are captured by Arizona itself. Next, we evaluate the cost efficiencies that would arise from a merger between Union Pacific and Burlington Northern Santa Fe. We find that such a merger would reduce costs by 17.1% due to reduced misallocation and process innovation. Lastly, we study the effect of the China shock on freight costs. We show that the reallocation of imports toward the West Coast led to a 3% increase in shipment costs in Los Angeles and Chicago, with heterogeneous effects across space and firms.