This isn't about grammar - it's about phonology. The basic rule is extremely simple: we use 'a' when the following word begins with a consonant sound, and we use 'an' when the following word begins with a vowel sound. Note that this is about SOUNDS, not spelling.
In most cases, we pronounce the 'h' at the beginning of words. This is a consonant sound, so we use 'a'. For example:
a hat
a house
a hamburger
However, there are a few words beginning with 'h' where the 'h' is silent. Words which have a silent 'h' begin with a vowel sound, so they are preceded by the article 'an'. The most important of these words is 'hour', which is pronounced exactly the same as 'our' - as if the 'h' were not there. The word 'honour' (spelt 'honor' in American English) also has a silent 'h'. Here are some examples:
an hour
an hourly service
an honour
an honest man
There are also a few words where the 'h' is sometimes pronounced and sometimes not:
a hotel ( usual in modern English)
an hotel (formal/outdated English)
an historic moment (rather formal and old-fashioned)
a historic moment (acceptable in modern English)
an herb (only in American English)
a herb (elsewhere in the English-speaking world)
I hope that helps.