They are used to symbolise a country. Either that, or they are used to wave around and look good. Flags can be used to show that the queen is at home!!! Or other reason's, like to show ships whether...
The original purpose of flags was to identify the nationality (or faction) of a given group of soldiers on a battlefield. Subsequently it has been used as a national symbol.