When do you use “a” or “an” ?

The two indefinite articles a and an are used with singular nouns when the noun is general. They refer to nouns which are non-specific (i.e. not definite). In other words, they refer to a particular thing that is not specifically known to the person who is making reference to that noun.

You should use “a” before nouns beginning with consonant sounds. An exception to this is a initial consonant silent “h” where it would be used for example, before the words; heir, hour, honor and honest. There are no audible sound and the sound that follows the article is a vowel. Thus, an should be used. However, when a word begins with an aspirated h such as house, hotel, hill and so on, then the article used is an. Some nouns beginning with consonant sounds are; a bottle, a picture, a broom, a store, a garage, a European and a red apple. It is also used before words beginning with consonants (b, c, d, f, g, h, j, k, l, m, n, p, o, r, s, t, v, w, x, z). It should also be noted that a can be used before words which begin with vowels (a, e, i, o, u,) but which are pronounced with an initial consonant sound. Here are two words for example which are pronounced with an initial y sound (yoo) and are treated as a consonant, requiring a:i) words beginning with a long u (when pronounced as yoo) such as; utility, union, ubiquitous, united, unique, university and so on used a before these words.
ii) words beginning with eu such as eulogy and euphonium, used a before it.

On the other hand, you should use the word “an” before all vowel sounds. These are words which start with the letters a, e, i, o and u. Some examples are: an entry, an hour, an apricot, unbeliever, an orange, an ape, an unusual problem, an odor, an eye, an idea, an eagle, an orbit, an honor, an umbrella, an elephant and so on. Thus, when nouns start with a vowel, then the article used is an.

So the choice of article is based upon the sounding of the first letter in a word rather than on the letter itself.