To begin to answer this question, we must first define what we mean by nationalism. For many people, it is just the natural attachment to home, the place one grew up. These feelings, however, obviously do not exist in a social vacuum. Nationality, as Bakunin noted, is a "natural and social fact," as "every people and the smallest folk-unit has its own character, its own specific mode of existence, its own way of speaking, feeling, thinking, and acting; and it is this idiosyncrasy that constitutes the essence of nationality." [The Political Philosophy of Bakunin, p. 325]
Perhaps it is in the interest of anarchists to distinguish between nationality or ethnicity (that is, cultural affinity) and nationalism (confined to the state and government itself) as a better way of defining what we support and oppose -- nationalism, at root, is destructive and reactionary, whereas ethnic and cultural affinity is a source of community, social diversity and vitality.
Such diversity is to be celebrated and allowed to express it itself on its own terms. Or, as Murray Bookchin puts it, "[t]hat specific peoples should be free to fully develop their own cultural capacities is not merely a right but a desideratum. The world would be a drab place indeed if a magnificent mosaic of different cultures does not replace the largely decultured and homogenised world created by modern capitalism." ["Nationalism and the 'National Question'", Society and Nature, pp. 8-36, No. 5, pp. 28-29] But, as he also warns, such cultural freedom and variety should not be confused with nationalism. The latter is far more (and ethically, a lot less) than simple recognition of cultural uniqueness and love of home. Nationalism is the love of, or the desire to create, a nation-state. And for this reason anarchists are opposed to it, in all its forms.
This means that nationalism cannot and must not be confused with nationality. The later is a product of social processes while the former to a product of state action and elite rule. Social evolution cannot be squeezed into the narrow, restricting borders of the nation state without harming the individuals whose lives make that social development happen in the first place.
The state, as we have seen, is a centralised body invested with power and a social monopoly of force. As such it pre-empts the autonomy of localities and peoples, and in the name of the "nation" crushes the living, breathing reality of "nations" (i.e. peoples and their cultures) with one law, one culture and one "official" history. Unlike most nationalists, anarchists recognise that almost all "nations" are in fact not homogeneous, and so consider nationality to be far wider in application than just lines on maps, created by conquest. Hence we think that recreating the centralised state in a slightly smaller area, as nationalist movements generally advocate, cannot solve what is called the "national question."
Ultimately, as Rudolf Rocker argues, the "nation is not the cause, but the result of the state. It is the state that creates the nation, not the nation the state." [Nationalism and Culture, p. 200] Every state is an artificial mechanism imposed upon society by some ruler in order to defend and make secure the interests of privileged minorities within society. Nationalism was created to reinforce the state by providing it with the loyalty of a people of shared linguistic, ethnic, and cultural affinities. And if these shared affinities do not exist, the state will create them by centralising education in its own hands, imposing an "official" language and attempting to crush cultural differences from the people's within its borders.
Hence we see the all too familiar sight of successful "national liberation" movements replacing foreign oppression with a home-based one. This is unsurprising as nationalism delivers power to local ruling classes as it relies on taking state power. As a result, Nationalism can never deliver freedom to the working class (the vast majority of a given "nation"). Moreover, nationalism hides class differences within the "nation" by arguing that all people must unite around their supposedly common interests (as members of the same "nation"), when in fact they have nothing in common due to the existence of hierarchies and classes. Its function is to build a mass support base for local elites angry with imperialism for blocking their ambitions to rule and exploit "their" nation and fellow country people:
"[W]e must not forget that we are always dealing with the organised selfishness of privileged minorities which hide behind the skirts of the nation, hide behind the credulity of the masses [when discussing Nationalism]. We speak of national interests, national capital, national spheres of interest, national honour, and national spirit; but we forget that behind all this there are hidden merely the selfish interests of power-loving politicians and money-loving business men for whom the nation is a convenient cover to hide their personal greed and their schemes for political power from the eyes of the world." [Rudolf Rocker, Op. Cit., pp. 252-3]
Moreover, the Nation has effectively replaced God in terms of justifying injustice and oppression and allowing individuals to wash their hands of their own actions. For "under cover of the nation everything can be hid" argues Rocker (echoing Bakunin, we must note). "The national flag covers every injustice, every unhumanity, every lie, every outrage, every crime. The collective responsibility of the nation kills the sense of justice of the individual and brings man to the point where he overlooks injustice done; where, indeed, it may appear to him a meritorious act if committed in the interests of the nation." [Op. Cit., p. 252] (perhaps, in the future, the economy will increasingly replace the nation just as the nation replaced god as the means of escaping personal responsibility of our acts? Only time will tell, but "economic efficiency" has been as commonly used to justify oppression and exploitation as "reasons of state" and "the national interest" have been).
Thus anarchists oppose nationalism in all its forms as harmful to the interests of those who make up a given nation and their cultural identities. However, anarchists are opposed to all forms of exploitation and oppression, including imperialism (i.e. a situation of external domination where the ruling class of one country dominates the people and territory of another country - see section D.5). While rejecting Nationalism, anarchists do not necessarily oppose national liberation struggles against such domination (see section D.7 for details). However, it goes without saying that national "liberation" movements that take on notions of racial, cultural or ethnic "superiority" or "purity" or believe that cultural differences are somehow "rooted" in biology get no support from anarchists.