Excessive credit growth and high asset prices increase the probability of a crisis. Because these two variables are determined in equilibrium, the analysis of systemic risk and the cost-benefit analysis of macroprudential regulation requires a specific framework consistent with the empirical observation. We argue that an overlapping generation model of rational bubbles can explain some of the main features of banking crises and, therefore, provide a micro founded framework for the rigorous analysis of macroprudential policy. We find that credit financed bubbles may have a role as a buffer in reducing excessive investment at the firms' level and, thus, increasing efficiency. Still, when banks have a risk of going bankrupt a trade-off appears between financial stability and efficiency. When this is the case, macroprudential policy has a key role in improving efficiency while preserving financial stability.