A, an
tl;dr: Use 'an' when a vowel sound follows, 'a' when s consonant sound does.
Sound, not character; in writing too, it should be based on pronunciation. This makes it depend on accent and dialect a little.
For example: the h in herb is often silent in American (an herb), but not in British English variants (a herb). Similarly, 'a hotel', unless you pronounce it like 'otel'.
In such cases, one form is usually (strongly) preferred over the other.
When writing, there are a few cases that should make you stop and check, including:
An h, when it is silent:
- an honest man
A u that is pronounced like a y:
- a used napkin
- a unique parameter
- a US ship
An o that gets peonounced like a w:
- a one-pegged pirate
Note that anything subject to unusual pronunciations could be an exception case. Consider also initialisms/acronyms:
- an MP
- a US ship
- an LBA
- an SMTP server
Note that when acronyms have varying pronunciations (e.g. URL, LED), both a an an can be correct.