I'm sure it is not official, but the crescent is on mosques and flags, etc. what is the history behind it?
There's an OK entry on this by Yuka Kadoi in the third edition of the Encyclopedia of Islam, if you have access. The first crescent moon, or hilal, is used to determine the beginning of months, and so is associated with many important days in the Islamic calendar, including the beginning and end of Ramadan. Its use as a symbol of Islam is fairly late, though, and its history isn't particularly straightforward.
Kadoi notes that it appears on 7th century Arab-Sasanian coins, and that this is the first official use of the symbol by an Islamic government. This is true, but as she notes, this usage had disappeared by the 8th century, and more importantly, 7th century coinage is a bit strange. The contemporary Arab-Byzantine coins of Syria, for example, at first borrow quite heavily from Byzantine and Christian iconography that we wouldn't associate with Islam, and the Arab-Sasanian coins, likewise, borrow very heavily from Sasanian iconography. The late 7th century coinage reforms of 'Abd al-Malik eventually introduced completely aniconic coins, and this was, for quite a while, the standard.
Kadoi notes that the crescent moon symbol next appears in the 12th century on Zangid coins minted in Mosul. It also appears on later Ilkhanid coins, also from Mosul. This might be a symbol specific to Mosul, or a Turkish one, considering its later connection to the Ottomans.
A variety of sources — many of them, like this one and this one, rather old now — argue that the crescent moon as a symbol of Islam first appears as a symbol of the Ottomans, specifically. (Kadoi is a bit vague on the chronology here, unfortunately, but notes that the most important development was its use as a symbol on military banners.) There seems to be a consensus that the crescent moon as a symbol of Islam actually first emerges among European states in conflict with the Ottomans, and that it's in this context that it is later adopted as a symbol by Muslims themselves. Donald Reid — who is actually a historian of France, but still — relates a story of a mid-18th century Ottoman ambassador to France being surprised by the association of the crescent with Islam — I wish I could find another source for this anecdote, because it sounds fascinating. Reid argues that it isn't until the late 18th century, at least, that this association is made in the Ottoman Empire.
So, to sum up, the symbol of the crescent moon — and even the crescent moon and star combination — is certainly pre-Islamic. There's nothing to indicate that the symbol was particularly associated with Islam in pre-Ottoman contexts, though we can certainly find examples of its use. It's only with the Ottomans — and, even then, potentially relatively late — that the symbol becomes associated with Islam, probably first by Europeans and only later by Muslims themselves. (Incidentally, a number of theories have also been put forward for why the Ottomans adopted the symbol — perhaps because it looks like a horseshoe. Perhaps they took it from the Byzantines. Perhaps it's related to the earlier Zangid usage. And so on — and the short answer there is also probably that we don't exactly know.)