While "a" is generally used before words starting with consonant sounds, there are exceptions:
* Words starting with a vowel sound, even if spelled with a consonant: "a university" (because "u" has a vowel sound), "a one-time offer" (because "o" has a vowel sound)
* Words starting with a silent "h": "an hour", "an honest man"
The rule of thumb is to use "a" before consonant sounds and "an" before vowel sounds.