We use a massive, matched employer-employee database for the United States to analyze the contribution of firms to the rise in earnings inequality from 1978 to 2013. We find that one-third of the rise in the variance of (log) earnings occurred within firms, whereas two-thirds of the rise occurred due to a rise in the dispersion of average earnings between firms. However, this rising between-firm variance is not accounted for by the firms themselves but by a widening gap between firms in the composition of their workers. This compositional change can be split into two roughly equal parts: high-wage workers became increasingly likely to work in high-wage firms (i.e., sorting increased), and high-wage workers became increasingly likely to work with each other (i.e., segregation rose). In contrast, we do not find a rise in the variance of firm-specific pay once we control for the worker composition in firms. Finally, we find that two-thirds of the rise in the within-firm variance of earnings occurred within mega (10,000+ employee) firms, which saw a particularly large increase in the variance of earnings compared with smaller firms.