The rules when to use "a" and when to use "an" are as follows.
If the word starts with a consonant sound you should use a
If the word starts with a vowel sound you should use an
Some words can be a bit tricky.
The words yellow and young begin with a consonant sound.
The word hour begins with a vowel sound.
The best is to say the word out loud and hopefully you hear if it is a consonant sound or a vowel sound.