We move beyond the nation-state as the unit of analysis and use subnational spatial variation to study the effect of the institutional environment on international trade. Additionally, we address the heterogeneous effect of trade agreements on different regions within a country. Employing a gravity model approach, we use a region-to-country dataset to estimate the determinants of Spanish regional exports and we apply quantile regressions for panel data. We find that better institutional quality of trade agreements leads to an increase in both the intensive and the extensive margins of trade. The institutional quality of trade agreements exerts a differential effect on regional exports at different locations within a country, although differences across Spanish regions seem to be larger for the intensive margin than for the extensive margin. We do, however, find a common trend: for the relatively more important exporting regions, the institutional quality of TAs is less relevant for trade margins. Therefore, our results posit that subnational spatial variation should be added to the analysis of the determinants of international trade flows.