According to the usually excellent (unfortunately not so much this time) Robert Higgs, Nationalism Is a Weird Ideology.
Nationalism is a weird ideology. It would be easy to imagine that it was cooked up by rulers looking for a means of keeping their victims submissive and cooperative.
Actually nationalism is not a weird ideology at all: you just need to understand why it exists. Certainly it is very often abused for the benefit of the rulers who need to keep their victims submissive; but maybe it is also useful for something else, like motivating and achieving large scale cooperation among nationals, which can be necessary for large scale tasks like war making; and perhaps even submission is not wholly bad, specially if voluntary, if many people need to submit to some higher authority in order to live together and coordinate their cooperation.
A nationalist gives moral priority to others within the boundaries of his nation-state, or at least to his fellow citizens there, and he acts accordingly in political affairs. Yet even in a small nation-state, practically all these people are complete strangers. One has never met them, never will meet them, has only the foggiest idea of the sort of people they are. Maybe they speak his language, but many do not. Maybe they are of the same race, but many are not; and even if they are, so what? Maybe they share his cultural affinities, but maybe they don’t. Maybe they are not even decent people; in fact, many are complete creeps or criminals. Why should anyone give any kind of priority to them merely because they happen to be located within the boundaries of the same tax farm?
Of course a member of a group of a certain kind, like a political unit, gives some moral priority to other members of that group: that is what defines that group as a unit of mutual help, shared possession of some goods, common interests and collective action; members of the group are legally treated differently from non members, they have special rights and duties regarding each other and the group as a whole. That is what being a citizen of a nation is about: it is not the same as not being a citizen, and the differences matter.
Of course most individuals in a nation, being many, are perfect strangers and probably very different: the population of a nation exceeds by orders of magnitude the number of personal relationships any individual can have; and the more members a group has, the more differences there probably are. But this is not an argument for the weirdness of nationalism, but exactly the opposite: this is what makes nationalism understandable as a way to build an imagined community. Perfect strangers cannot coordinate directly or personally, and different people need something that unites them in spite of their differences: they need an idea that represents the community they all belong to, a feeling of belonging to it, and a motivation to submit to it and defend it; therefore they have the nation and nationalism, with their shared territory, history of disasters and achievements, heroes, enemies, flags, hymns and leaders.
There are other possible types of political groups with different ways of uniting and identifying themselves: clans, tribes, regions, kingdoms, empires; nations are just one more variety. Other ideas or phenomena can either replace nationalism, complement it or work against it: ethnicity, language, culture, religion.
Small homogeneous units can work better internally because more similar members understand each other easily and have more common local knowledge and interests; but a small group might not be able to survive against other possibly hostile bigger groups. Nationalism can help build a stronger aggregate.
Big political units like empires can be very powerful, but they are hard to cohere and govern, and internal conflicts can cause serious problems. Nationalism can help produce more manageable units, or it can help a subgroup cohere and consolidate against the submission to a bigger one and thus attain independence.
Nationalism is, among other things, a gigantic aggregation error. It takes a huge, enormously diverse collection of people and imagines that each and every individual in the collection is somehow better than each and every individual in other nation-states. The more you think about it, the more idiotic it becomes.
Nationalism is obviously about aggregation, but it is not necessarily an error. It does not imply that every national is better than every non national. It does imply that they are different, that they are the ones we happen to live together with inside our imagined community versus the ones who are outside in their own separate communities. You do not have to think much in order to understand this. It actually might seem idiotic not to understand it.
Of course nationalism can have many problems and drawbacks: you might not like other citizens of your nation, some being creeps or criminals; you might prefer non nationals as neighbors or friends; you might have a cosmopolitan character and aspire to a world without political units except mankind; nationals might feel too proud of their nation and dismissive of other peoples, my country wrong or right; nationalism might erect barriers to trade; it might be aggressive against other nations instead of merely defensive; it might be used by foreign powers in order to divide rival alliances; political leaders might use it in order to divert attention from real problems and their shenanigans.
Nevertheless nationalism is not by itself the root and cause of all evils, unless of course you want to load the term with every possible negative connotation you can imagine, like racism, xenophobia, closed borders, selfishness, authoritarianism, totalitarianism and war; and then you will probably use other nice words for the good groupishness, like patriotism or republicanism.
There can be many kinds of nationalism, from statist, collectivist, communist, socialist, fascist nationalism, to liberal nationalism. But nationalism is not weird, just peculiar, like every other ideology.