'An’ should be followed by a vowel (a,e,i,o,u), and 'a' should be followed by a consonant.
But this is not always true!
When using either of them, pay attention to pronunciation, and not on how the noun is written:
-The word hour has a soft ‘h’ which is weakly pronounced, and therefore we say ‘an hour’
-The word house has a hard ‘h’, so we pronounce 'a house'
Said otherwise, use 'an' before nouns that start with a vowel when pronouncing them, and 'a' before everything else.