I think your ear is out of it. Historically it was an whether the next word started with a vowel or a consonant or whatever. Over time the n got itself elided into the following consonant. It's still a little up in the air if the consonant is an h, see an historic vs. a history. Otherwise, vowel, an, consonant or semivowel (y,w), a.