The choice comes down to one question: does my listener already know which one I mean?
- No, this is new information → a / an. I saw a dog.
- Yes, they know exactly which → the. *The dog was barking. (the one I just mentioned)*
- I'm talking about the thing in general, not a specific one → no article. I like dogs.
That last case is the one Spanish speakers miss most, because Spanish keeps the article: Me gustan los perros → I like ~~the~~ dogs.
a or an?
It follows the sound, not the letter. an before a vowel sound: an apple, an hour (the h is silent). a before a consonant sound: a car, a university (it starts with a y sound).