Remember articles? They’re basically adjectives, which means they modify nouns.
English has only three articles—a, an, and the. The first two are called indefinite articles, because they’re non-specific. The, on the other hand, is a definite article, because it refers to a particular noun. So when Bob Marley wrote “I Shot the Sheriff,” he wasn’t referring to a random law enforcement officer. He had someone specific in mind. If he’d written “I Shot a Sheriff,” well…it would have been a completely different song.
So how do you know whether to use a or an? Depends on what comes next. Use an if the word that comes next begins with a vowel sound; use a if the word that comes next begins with a consonant sound. An egg, for instance, but a broken egg. See, it doesn’t matter that both a and an modify egg; what matters is the word that immediately follows the article.
Notice I wrote vowel and consonant “sound”? Words like hour begin with a silent consonant but are pronounced with a vowel sound. So: an hour. But it’s a habit, a house, a horse, etc. The reverse is also true: university is one of a handful of words that begin with a vowel but are pronounced with a consonant sound. The same is true for abbreviations: an FBI agent, a UN peacekeeping operation…you get the idea.
If you’re stuck, try saying it out loud. Your ears will know the difference.