The rule is: Use an before a word beginning with a vowel sound (not letter). It doesn't matter how the word is spelled. It just matters how it is pronounced. Use a before a word with a consonant sound as well as y and w sounds.
What is the rule for using a or an?
The indefinite article an is used to make pronunciation easier when reading a text aloud. The general rule is to use a when the indefinite article precedes a word beginning with a consonant sound and an when it precedes a word starting with a vowel sound.
When not to use a or an?
Here's the secret to making the rule work: The rule applies to the sound of the letter beginning the word, not just the letter itself. The way we say the word will determine whether or not we use a or an. If the word begins with a vowel sound, you must use an. If it begins with a consonant sound, you must use a.