We study a dynamic economy where credit is limited by insu¢ cient collateral and, as a result, investment and output are too low. In this environment, changes in investor sentiment or market expectations can give rise to credit bubbles, that is, expansions in credit that are backed not by expectations of future proÖts (i.e. fundamental collateral), but instead by expectations of future credit (i.e. bubbly collateral). Credit bubbles raise the availability of credit for entrepreneurs: this is the crowding-in e§ect. But entrepreneurs must also use some of this credit to cancel past credit: this is the crowding-out e§ect. There is an ìoptimalî bubble size that trades of these two e§ects and maximizes long-run output and consumption. The equilibrium bubble size depends on investor sentiment, however, and it typically does not coincide with the ìoptimalîbubble size. This provides a new rationale for macroprudential policy. A credit management agency (CMA) can replicate the ìoptimalîbubble by taxing credit when the equilibrium bubble is too high and subsidizing credit when the equilibrium bubble is too low. This leaning-against-the-wind policy maximizes output and consumption. Moreover, the same conditions that make this policy desirable guarantee that a CMA has the resources to implement it.