Firms are increasingly outsourcing their high-tech services. Theory suggests that R&D outsourcing allows firms to specialize in core knowledge-intensive tasks, thereby increasing innovation, but R&D outsourcing may also undermine internal capabilities. Our goal is to empirically assess the relative importance of these two possibilities, distinguishing between national and international R&D outsourcing and firms' exporting status. We examine R&D purchases of more than 10,000 Spanish firms for the period 2004-2014. We show that R&D outsourcing improves firm innovation. Product innovation rises mostly with domestic outsourcing, while process innovation increases with both domestic and international R&D outsourcing. In addition, we find that international outsourcing provides an extra premium, mostly for exporters. Our results contribute to a better understanding of how firms organize the production of knowledge and innovation.