This paper provides an economic framework for examining how economic openness affects nationalism. Within a country, a region's level of nationalism varies according to its economic interests in its domestic market relative to its foreign market. All else being equal, increasing a region's foreign trade reduces its economic interests in its domestic market and thus weakens its nationalism. This prediction holds both cross-sectionally and over time, as evidenced by our empirical study using the Chinese Political Compass data and the World Value Surveys. Our framework also applies to analysis of nationalism across countries and receives support from cross-country data.