Maritime flag signalling, generally flaghoist signalling, is the principal means other than radio by which ships communicate to each other or to shore (distinguished from flags showing nationality, ownership, or (for naval vessels) organizational status). Virtually all signalling by non-naval vessels is now organized under the International Code of Signals (whether by flaghoist, semaphore, signal lamp, or other means), which specifies a standard set of flags and codes. Naval vessels generally use an extended set of flags and their own codes. This article will touch on the historical development of maritime flag signalling.
In the early days of sail, the use of signals to communicate between ships was primitive, as seen by one admiral's instructions to his fleet in 1530:
"Whensoever, and at all tymes the Admyrall doth shote of a pece of Ordnance, and set up his Banner of Council on Starrborde bottocke of his Shippe, everie shipps capten shall with spede go aborde the Admyrall to know his will."
By 1653, the Royal Navy had issued instructions by which an admiral could signal various orders by hoisting flags in various locations on his ship. Modern naval code signalling began with the invention of maritime signal flags in the mid-17th century by the then-Duke of York (subsequently James II) who was created Lord High Admiral after the Restoration. A ship's message had to be approved by the officer of the watch, and his system was augmented and changed in various ways over the following century. In 1790, Admiral Lord Howe issued a new signal book for a numerary system, using numeral flags to signal a number; the number indicated the message, not the mast from which the flags flew. Substitute flags were also instituted to indicate repeated numerals, and there was consideration of making the flags more distinct.
A numerical flag code using ten coloured flags was proposed by Bertrand-François Mahé de La Bourdonnais in 1738. Bourdonnais proposed hoisting the flags in groups of three, making a thousand possible messages that could be transmitted by reference to a code book. His idea was not taken up at the time, but it was noticed by Ignace Chappe, the brother of Claude Chappe. The Chappes developed an optical land telegraph which used a numerical code book with many thousands of messages.
In 1763, Sebastian Francisco de Bigot, the founder of the Académie de Marine in Brest, published Tactique Navale ou Traite des Evolutions et des Signaux. This was the first established system for coded flags with a defined protocol for using them. The code had 336 possible signals. De Bigot's book was published in England in 1767, but it was several decades before the Royal Navy developed their own system.
In 1799, Captain Sir Home Popham published his first list of words and sentences which could be referenced by a number (or "code"); three subsequent editions added letter flags, with the 1801 edition numbering 2994 codes. It was based on the signal books created earlier by Admiral Lord Howe. Popham's code assigned the digits 0 to 9 to ten signal flags, which were used in combination. Code numbers 1-25 represented letters of the alphabet (omitting J and with V=20 before U=21); higher numbers were assigned meanings by a code book. The code numbers typically would have been hoisted on the mizzenmast, one after another, preceded by the "telegraphic flag" (a red over white diagonally-split flag) to show that the subsequent signals would employ the Popham code. As well as digit flags, the code used "repeat" flags so that only one set of digits was needed; thus the word do, coded as "220", used a "2" flag, a "first repeat" flag here serving as a second 2, and a "0" flag. The end of the message would be indicated by an "end of code" flag (blue over yellow diagonally split).
Popham's code was famously used for the "England expects that every man will do his duty" signal at Trafalgar by Nelson: for this, a team of four to six men would have prepared and hoisted the flags onboard Lord Nelson's flagship HMS Victory, the whole process taking about 4 minutes. The message shows one of the shortcomings of Popham's code--even the two-letter "do" required three flags hoisted for the signal.
Previous systems were primarily naval. The first general system of signalling for merchant vessels was Captain Frederick Marryat's A Code of Signals for the Merchant Service published in 1817. This consisted of six parts of large numbered lists:
Different flags indicated which list was referred to. As an example, flying the Rendezvous (RE) flag (indicating Lighthouses, Ports, etc.) over the numerals 1537 indicates that the ship's home port is Amsterdam. Flying Rendezvous under the number indicated that the ship is sailing from Amsterdam, and flying it at some other mast-head indicates that she is bound for that port. Numbers alone indicate a sentence: "4576" means "I mean to keep sail set, and carry on all night, as I am anxious to get into port." Marryat's code was an immediate success and was translated into several other languages, and the 1854 edition was renamed The Universal Code of Signals for the Mercantile Marine of All Nations because of its widespread usage. The last edition was published in 1879, two decades after the publication of the code that supplanted it; there are reports that it was still being used as late as 1890.
Various other codes were also published, but all these were eventually supplanted by the Commercial Code of Signals published by the British Board of Trade in 1857, which eventually became the International Code of Signals (ICS). A significant development was the addition of letter flags to make the code alphabetical. (The vowels were initially left out to avoid formation of any objectionable words.)  During World War I, there was an unprecedented need for ships to communicate, merchant as well as naval, but the ICS was found wanting: "It was not international. It was found that when [signalling] word by word, the occasions upon which signaling failed were more numerous than when the result was successful." This led to major revisions in 1931. This new international code of signals was officially brought into force worldwide on 1 January 1934. Thirteen new flags were introduced, so that the triangular pennants used for letters, C, D, E, F, and G were replaced with new square flags and became the numerals 1, 2, 3, 4, and 5. The numerals 6, 7, 8, 9, and 0 were introduced by five new flags, and there were three substitute flags, used when repeating letters in a hoist. Additional changes in 1969 greatly reduced the Code (dropping the Geographical and Vocabulary sections), and more narrowly focused it on communications related to safety of navigation. An indication of the success of the ICS is that most navies now use the ICS flags for representing letters.