The star and crescent is a symbol for the former Ottoman Empire and began being used in the second half of the 18th-century. The decision to have a national flag was decided as part of reforms to modernize the Ottoman state in lieu of contemporary European states.
However, the star and crescent iconography developed during the 4th and 1st centuries BCE, during the Hellenistic period most notably during the Kingdom of Pontus, the Bosporan Kingdom, and the city of Byzantium (later Constantinople). The iconography was also used in the ancient Near East and represented either the sun and the moon, or the moon and the morning star.
By the 20th-century, the star and crescent also began to appear in the flags of Ottoman successor states such Tunisia, Algeria, and Azerbaijan, which continue to have this iconography in their national flags.
The current Turkish national flag was derived from the Ottoman version, except that the star and crescent symbols are thinner and have exact dimensions, which were standardized with the Turkish Flag Law of 1936.
One of the legends of the Turkish flag is that during the battle of Kosovo in 1448, when the Ottomans defeated the Christian forces, a reflection of the moon and star appeared in the pools of blood.
Another legend states that the first Ottoman Sultan Osman I, saw a dream where a crescent and star rose from the chest of the qadi (judge of the Shari’a court) whose daughter he wanted to marry, and then descended into his own breast and sprang a tree whose enormous branches covered the whole world with its shadow.
Even though it’s widely believed that the crescent and moon are a symbol of Islam, the symbol’s origins pre-date Islam and are believed to go back to the peoples of Central Asia and Siberia, whose worship of the sun, moon, and sky gods made use of these celestial symbols.
Another theory states that the symbols were supposedly used to honor the Greek goddess of Diana, and the city of Byzantium (which later became Constantinople and then Istanbul) chose them.
When the Ottoman Empire conquered Constantinople in 1453 they adopted the flag of Byzantium because of the dream that Osman I had, which he believed to be a good omen and therefore a good symbol for his new empire.