we usually learn in school that it depends on the first letter of the word
a,e,i,o,u => an
other letters => a
but that isn't always right. It usually depends on the pronounciation of the first letter.
The a,e,i,o,u stuff works, but only for a,e,i,o
for example you say 'a uniform', because it's prnounced as 'yuniform'
another example is 'an hour', because you don't say the h (so the first letter would be 'o')
I'm really sorry that I can't express myself that well to explain it better, but I hope I could help you a little.
But being not a Native Speaker has its advantages......You have to learn everything about the english language in school, and then even even some Native Speakers are puzzled about what we learn. (Because sometimes Native Speakers don't really have an explanation for things, that seem so easy to us.)
Student or Learner