Although the flag is most commonly associated with the European Union, it was initially used by the Council of Europe, and is thought to represent Europe as a whole as opposed to any particular organization such as the EU or the COE.
The flag was originally adopted by the Council of Europe on December 8, 1955, from a suggested design by the Chief Herald of Ireland. The Council of Europe from the beginning desired it to be used by other regional organizations seeking European integration. The European Community adopted it on May 26, 1986. The European Union, which was established by the Maastricht Treaty in the 1990s and is a somewhat different co-existing organisation formed by members of the European Community, also adopted the flag. Since then the use of the flag has been controlled jointly by all three organizations.
The number of stars on the flag is not related to the number of member states of EU. 
History accompanying the flag
The Council of Europe was formed in the aftermath of the Second World War. 1955
The Council of Europe creates for itself what is now also the EU flag, as a focus for European unity 1957
European Economic Community founded by the Treaty of Rome: Belgium, France, Germany, Italy, Luxembourg and the Netherlands - "The Six" 1967
European Community formed by a merger of the EEC, Euratom founded 1957) and The European Coal & Steel Community (founded 1951) 1973
United Kingdom joined the EC, together with Ireland and Denmark making "The Nine" (Norway opted to stay out) 1981
Greece joined, making "The Ten" 1986
EC adopts (with permission) the Council of Europe Flag as its own. 12 Stars & 12 States. 1992
Maastricht Treaty 1993
Maastricht Treaty Ratified. European Single Market completed. The European Union is launched. 1995