These two words often get misused because what sounds right
doesn't always mean it is right. So here's the rule...
Use 'a' when the next word does not sound like it starts with a vowel
Use 'an' when the next word does sound like it starts with a vowel
The key here is sound. For example, "honest" sounds like it begins with an 'o' and thus gets 'an' in front of it. On the other hand, "union" sounds like it starts with a 'y' and thus gets 'a' in front of it.