The red flag with the white crescent and star is one of the most recognizable national symbols on Earth, and most people attach it to the wrong state. It is the flag of the Republic of Turkey, but it was created by the Ottoman Empire, adopted in 1844 by a sultan trying to modernize a six-century-old dynastic realm into something resembling a European nation-state. The republic that overthrew the sultanate in 1922 discarded the dynasty, the caliphate, the alphabet and the capital, and kept the flag. That makes the Ottoman national flag a rare case of an imperial emblem that never went out of service.
An empire of many banners
For most of Ottoman history, asking "what was the Ottoman flag?" is a category error. The empire had banners, plural, and they marked institutions rather than the nation. The oldest were not flags at all: tughs, standards of horse tails mounted on poles, denoted rank, with the sultan entitled to more tails than his viziers. War flags of the 16th and 17th centuries often bore the Zulfiqar, the split-bladed sword of Ali, and religious inscriptions; the sultans also possessed the Banner of the Prophet, a relic carried on campaign. The navy flew red flags, the color long associated with Ottoman sovereignty, while green marked religious institutions. European flag charts of the 18th century, like Bowles's 1783 sheet, struggled to keep up, listing separate "Turkish" flags for Constantinople, the fleet and various officials.
Crescents appear on Ottoman banners from early in the empire's history, often plain white on red or green. What did not exist was a single flag standing for the state itself. That idea had to be imported.
Selim III puts a star on the navy
The first standardization came from the fleet. Sultan Selim III, who spent his reign (1789-1807) trying to rebuild the Ottoman military on European lines, issued a decree in 1793 requiring ships of the navy to fly red flags bearing a white crescent and star. The star of this period had eight points, and flags with six or seven points also turn up in the record; consistency was aspiration rather than fact. This naval flag functioned as the state's standard for the next half century, which is why European sources of the early 19th century show the Ottoman flag with a many-pointed star that looks slightly off to modern eyes.
1844: the Tanzimat flag
The decisive step came under Sultan Abdülmecid I as part of the Tanzimat, the sweeping reorganization of the empire launched in 1839. The reformers rebuilt the army, the tax system, the legal code and the bureaucracy on European models, and a state remaking itself in that image needed the basic kit of a modern state, including a national flag. In 1844 the empire adopted one: a red field with a white crescent and, beside it, a white five-pointed star.
The choice consolidated rather than invented. Red was the established sovereign color, the crescent was already the empire's best-known emblem, and the star had been on naval flags for fifty years; the 1844 flag trimmed the star to five points and made the whole arrangement official everywhere, on land and sea, for a state that stretched from the Balkans to the Persian Gulf. For the remaining 78 years of the empire's existence this was the Ottoman flag, flown through the Crimean War, the constitutional revolutions, the Balkan Wars and the First World War.
Where the crescent and star came from
No Ottoman document explains the symbolism, which has left the field open for a long scholarly argument. The historian Franz Babinger suggested the crescent was taken over from Byzantine tradition: the crescent was an emblem of the city of Byzantium going back to antiquity, associated with its patron goddess, and appears on the city's coinage centuries before 1453. On this theory the conquerors absorbed the symbol of the city they took. Turkish historians have countered that crescent imagery appears among Turkic states of Central Asia well before the Ottomans reached Constantinople. Star and crescent together appear in Ottoman battle imagery from the 16th century, including depictions of Mohács in 1526, but as decoration rather than fixed state emblem.
The popular legends are later and worse documented: a crescent reflected in blood after the Battle of Kosovo, a dream of the dynasty's founder Osman. They are stories about the flag, not sources for it. What is certain is the sequence: crescent first, by centuries; star late; five points only from 1844.
The empire ends, the flag does not
The Ottoman Empire was dissolved in 1922, when the Grand National Assembly in Ankara abolished the sultanate; the republic followed in 1923. Nearly everything imperial was swept away in Atatürk's reforms, but the flag stayed, too widely fought under and mourned under in the previous decade of war to be replaceable. The Turkish Flag Law of 1936 gave the old design its modern rigor: exact proportions of 2:3, the crescent's circles and the star's position defined to fractions of the flag's width, the red specified precisely. Later regulations carried the specifications forward.
The 1844 flag also cast a long shadow beyond Turkey. Ottoman prestige made the crescent and star read as a general emblem of Islam, and successor and sympathetic states adopted variations: Tunisia's flag, adopted under an Ottoman-influenced bey, is a close cousin; Libya, Algeria, Pakistan, Malaysia and others carry the pairing in their own colors. A device that may have started on Byzantine coins ended up on a dozen national flags, transmitted by an empire that only got around to having a national flag of its own in 1844.
References
[1] "Flags of the Ottoman Empire," Wikipedia, covering tughs, Zulfiqar banners, the 1793 naval decree and the 1844 national flag. https://en.wikipedia.org/wiki/Flags_of_the_Ottoman_Empire
[2] "Flag of Turkey," Wikipedia, on the continuity with the Ottoman flag and the Turkish Flag Law of 1936. https://en.wikipedia.org/wiki/Flag_of_Turkey
[3] Babinger, Franz, entries on Ottoman emblems discussing the Byzantine crescent theory, in Encyclopaedia of Islam.
[4] Bowles's Universal Display of the Naval Flags of All Nations (1783), contemporary chart recording multiple Ottoman naval flags.
[5] Smith, Whitney. Flags Through the Ages and Across the World (1975). McGraw-Hill.