Historically, flags originate as military standards, used as field signs. The practice of flying flags indicating the country of origin outside of the context of warfare became common with the maritime flag, introduced during the age of sail, in the early 17th century. The origins of the Union Jack flag date back to 1603, when James VI of Scotland inherited the English and Irish thrones (as James I), thereby uniting the crowns of England, Scotland and Ireland in a personal union (which remained separate states). On 12 April 1606, a new flag to represent this regal union between England and Scotland was specified in a royal decree, according to which the flag of England (a red cross on a white background, known as St George's Cross), and the flag of Scotland (a white saltire on a blue background, known as the Saltire or St Andrew's Cross), would be joined together, forming the flag of Great Britain and first Union Flag.
With the emergence of nationalist sentiment from the late 18th century the desire was felt to display national flags also in civilian contexts, notably the US flag, in origin adopted as a naval ensign in 1777, which after the American Revolution began to be displayed as a generic symbol of the United States, and the French Tricolore which became a symbol of the Republic in the 1790s.
Most countries of Europe adopted a national flag in the course of the 19th and early 20th centuries, often based on older (medieval) war flags. The specifications of the flag of Denmark were codified in 1748, based on a 14th-century design. The flag of Switzerland was introduced in 1889, also based on medieval war flags. The Netherlands introduced two national flags in 1813 (either an orange-white-blue or a red-white-blue tricolour; the final decision in favour of red was made in 1937).
The Ottoman flag (now the flag of Turkey) was adopted in 1844. Other non-European powers followed the trend in the late 19th century, the flag of Japan being introduced in 1870, that of Qing China in 1890.
Also in the 19th century, most countries of South America introduced a flag as they became independent (Peru in 1820, Bolivia in 1851, Colombia in 1860, Brazil in 1822, etc.)