The general rule is "An" if the next word starts with a vowel and "A" if the following word starts with a consonant. But there are exceptions, and I do not know all of them.
Here's one that always bother me when writing a personal statement: is it 'an' MSc or 'a' MSc? MS Word suggests an 'an', and it sounds better to me too.
And the one I am stuck on right now is an "L" shaped building or a "L" shaped building? Once again, Word and I favours the 'an', but I'd like to take opinions on this.