'An' goes before vowel sounds, not vowels. 'A' goes before consonant sounds, not consonants. Examples of these specifications are:
A unicorn
An historic (formal)
A historic (modern)
Can't think of any more. Too tired.
Why can "historic" have both "a" and "an"? The word "History" is derived from French, in which "H", before "I", is a vowel. L'histoire is French history, in which "L' " is a masculine 'abbreviation' for Le histoire because of how the flow would be interrupted if said Le histoire. Therefore, the formal way of the English history is "an history", with a slightly silent "H" sound, and a slur from the an to history. The modern way of writing it is "a history" because English has become more choppy and more enunciated so as to clearly deliver and convey messages; thus, the "h" sound in history is pronounced, and so it is also correct to say"a history".