The general rule for the use of the indefinite article in modern English is: a is followed by a consonant; an is followed by a vowel. But a problem is caused by certain sounds which display properties of both consonants and vowels - in particular, the ‘semi-vowels’ /w/ and /j/, as heard at the beginning of wet and yet respectively. These are articulated in the same way as vowels (they are really very short versions of /u/ and /i/), but within the structure of a word they take up one of the positions used by consonants, at the beginning of a syllable, as in b-et, s-et, w-et, y-et.

Shakespearean English shows several cases where the modern rule does not operate. There are instances where an is used before /j/:
  There are also several instances where an is used before /h/ in ways that would not be heard today. In modern English, /h/ is used as a consonant, so that we say a horse not an horse. There is a contemporary usage trend where some people use an before h-words beginning with an unstressed first syllable, as in an historic occasion, but the crucial point is that this does not apply to words where the first syllable is stressed; people today do not (yet) say an history book.

However, in Shakespearean English we do find an also used when the h-word is monosyllabic or begins with a stressed syllable:

an eunuch Cor III.ii.114
an union Ham V.ii.266
an urinal TG II.i.37
an usurer MA II.i.174
an usurped Oth I.iii.337
an universal JC I.i.44

And a case where it is used before /w/:

an one AC I.ii.115
an habit Ham V.ii.187
an habitation 2H4 I.iii.89
an hair Tem I.ii.30
an hand Per II.ii.36
an hasty-witted body TS V.ii.40
an heretic WT II.iii.114
an heroical TC III.iii.248
an host AC II.v.87
an hostess TC III.iii.252
an house 2H4 I.iii.58
an humble E3 II.i.233
an humour H5 II.i.52
an hundred Cor IV.v.111
an hypocrite MM V.i.41