Very simple but confusing. We are taught in primary classes that we had to put ‘An before the adjectives or noun started with a vowel and ‘A’ before the adjective or noun starting with a consonant. But as we study further we came to know this was not all correct.

In higher classes, we studied the use of ‘Articles’. But, here we came to know, we studied that we have to put ‘An before the adjectives or nouns with the sound of vowels. For examples-
- A Union (correct) not An Union (incorrect).
- A University (correct) not An University (incorrect).
- A European (correct) not An European (incorrect).
YOUR ANSWER:
We only use ‘an’ before a vowel. Y is sometimes pronounced as a vowel. But commonly at the end of a word such as gym, cycle, baby, etc. when it has a long E sound. At the beginning of a word, Y has a ‘ya’ sound, not a vowel sound. So your answer would be ‘A year’ not ‘An year’.
Y can be either a vowel or a consonant depending on how it is pronounced (or so we were taught in elementary school – “A, E, I, O, U, and sometimes Y”).
Here we see that the word Union, University, and European starts with a vowel but not the sound of the vowel. It sounds like this- Yunion, Yuniversity, and Yuropean.
Similarly, if the sound of the words is of a vowel we have to put ‘An instead of ‘A’. For examples-
- An Hour (correct), A Hour (incorrect)
There are more examples you can explore over the internet.