This paper develops a search and matching model of mergers and acquisitions (M&A) and uses it to evaluate the implications of merger activity for aggregate economic outcomes. The theory is consistent with a rich set of facts on US M&A, including sorting among merging firms, a substantial merger premium and serial acquisition. It provides a sharp link between these facts and the nature of merger gains. At the micro-level, both complementarities between merging firms and productivity improvements of target firms are important in generating gains. At the macro-level, the model suggests a significant beneficial impact of M&A on aggregate outcomes — the contribution to steady state output is 14% and 4% for consumption — which occurs through the reallocation of resources across firms and equilibrium effects on firm selection and new entrepreneurship. Nevertheless, the economy is not efficient, suggesting a scope for policy improvements — a simple flat tax on M&A can raise steady state consumption as much as 2% relative to the laissez-faire equilibrium. In short, the boundaries of the firm can matter for macroeconomic outcomes.