“A” goes before words beginning with a consonant sound in English, and “an” precedes words with an initial vowel sound. Listen for the sound rather than looking at the initial letter. Many English words beginning with an “h” take “a” instead of “an.” But there are five, and only five, English words and their derivatives beginning with a silent “h.” These take “an.”
A horse, a handle, a hermit, and (notice!) a history.
An heir, an hour, an honest [person], an honor, and an herb.
Also watch for words starting with a vowel but which actually begin with a consonant sound.
unique, use, union, and eulogy all begin with a consonantal y sound and take “a” not “an.”