That European nations have existed for more than 300 years. For thousands of years, the borders between cultures (traditions, customs, languages) in Europe were much more fluid than today. It was not possible to say e. g. “These are the French”, “These are the Germans” and “These are the Italians”, because the cultures flowed into each other. People also did not feel French, German, Italian, whatever, because that thought only came up in the 18th century. People felt allegiance to their family and their village, not to larger cultural units.
There were countries, but the countries did not map onto cultures. They were either small kingdoms or large multi-ethnic empires whose monarchs usually acquired territory through inheritance, conquest or marriage, without thought to the culture or language of the people whose rulers they became. There was no patriotic resistance to this practice until the 18th century. For the most part, it wasn't a problem, because the administration was local, in the hands of feudal lords who did speak the local language and knew the local practices.
Several factors led to the creation of distinguishable cultural units:
Book-printing. It would have been too expensive to print books in the hundreds of languages / dialects spoken in Europe at the time, so printers supported the standardization of languages and the promotion of a few languages over others. Language is both an indicator and a means of creating different cultures, because different languages give access to different information, a different canon of folk tales and literature and so on.
The reformation created new cultural distinctions in Europe, because previously most had had the same beliefs, celebrated the same church holidays, used the same religious rituals and so on. It also encouraged people to think for themselves, starting a wave of secular philosophers.
States centralized their administration and weakened the feudal lords. This meant a need for a lot more state officials, i. e. career opportunities for those who felt loyal to the state. The introduction of national languages and national education circuits meant that officials, unlike feudal lords previously, could not hope to keep their position if the territory fell to another country. Officials within one country would network, while there was much less contact across the border, furthering cultural differences.
Later (this list is not chronological), with the advent of industrialization, which brought schooling to a much larger share of the population, the above affected everyone. (Even in our united EU, it is not simple to have one country's certificate recognized in another.) This contains people within one country's borders and gives them a certain stake in that country's situation. The exposure to the public school system also creates distinguishable cultures, especially when the state uses schools to spread a national narrative.
In the 19th century, all European countries introduced national holidays, museums and monuments telling the story of their nation, uniting people by making them feel part of the same history. In most cases, this history was a relatively new invention, first heard at most 100 years ago, even though it described the nation as having existed much earlier (e. g. in France every student learns: “our ancestors the Gauls…“).
The idea of nations
German philosopher Johann Gottfried Herder (1744-1803) was the originator of the idea that there are a number of distinguishable cultures in Europe. According to him, just as every human has his own character, formed by his past and his environment, so each people has its own culture and mentality, the Volksgeist, formed by its past, its environment and its livelihood. This was the birth of Cultural Nationalism. (Cultural because Herder did not talk politics at all)
Another German philosopher created Political Nationalism: Johann Gottlieb Fichte. He thought that each nation stands above its individual members and the members have common characteristics because of Volksgeist, distinguishing themselves from members of other nations. According to him, national awareness lay slumbering in the unconsciousness of its members but eventually had to come to the front. After becoming aware, each nation has the ability, through its national will, to decide its destiny by way of political struggle. The highest goal for a nation was the formation of a sovereign nation-state free of foreign influences. Fichte's philosophy created the picture of nationalism as an organic and natural development that each people was entitled to, when the truth is that none of the peoples in Europe's previous thousands of years of history had had a nationalist awakening. His philosophy has been used to justify all later nationalist movements, no matter if they're state nationalist, separatist or integralist in nature.
Fichte's ideas initially had very little traction in Europe, but sooner or later many governments and many people wanting to grab power saw the advantage of promoting the nationalist narrative.
There's an essay by Stan Verschuuren which really opened my eyes – he narrates not just what I just explained here, but also the further spread of the idea. He winds up telling the entire modern history of Europe, from the 19th century Polish revolts to the German reunification and the Scottish independence movement, through the lens of nationalism, its pre-requirements for success and its motivations. I loved this essay so much that I attempted a translation (originally in Dutch) into English, which you can find at Stan Verschuuren on Nationalism
“I have no country to fight for; my country is the Earth, and I am a citizen of the World.” – Eugene V. Debs