Generally the question is how words are pronounced (i.e. spoken). The purpose of the "n" in "an" is to allow a glide from one word to the other. it is easier to say "an apple" than it would be to say "a apple" (which is wrong).
However, at least in Great Britain, I have notivced that certain words, most of all the word "history" often come with "an", even though the "h" is clearly spo