Nationalities make up the foundation of a nation up a part of the identity of the people living in the country. The French Revolution of 1789 layed the path for the modern nation-state and resulted in the rise of nationalism. As a reaction to the Enlightenment, that emphasised national identity and developed a romantic view of cultural self-expression through nationhood, a wave of romantic nationality swept through Europe.
The invention of symbols for national identity became the concern for racial, ethnic and linguistic groups as they struggled to reposition themselves in the quickly changing power structures. Thus, nationalism was a way of re-identification that united people of one nation and reflected the contemporary perspective on the nation-state.
The people needed symbols to represent and express their nation. They often were reappropriated or borrowed from already existing structures such as the military, the navy and heraldry. The flag was a symbol that derived from warfare and already existing counties or regions just like the emblem or crest that countries took on to represent themselves came from century-old heraldic traditions.
Some national flags that are still used date back to the 9th century, like the first tricolour flag. Many were designed or reappropriated in the 19th century. National flags usually have a design of one or more symbolic colors and sometimes an icon. The symbolic value of the colours can vary from area to area: in one country, the colour red can symbolize the sword, in another blood and in another passion. A study called vexillology studies the meanings and backgrounds of all kinds of flags, such as national ones.
Many flags have, in fact, the same symbols, as you can see that on this website. Since national flags consist of generic elements, then why can we not create new ones infinitely?