The vowels in Spanish can be classified as either weak or strong, and the classification can determine when combinations of two or more vowels are considered to form a separate syllable.
The strong vowels of Spanish — sometimes known as open vowels — are a, e and o. The weak vowels — sometimes known as closed vowels or semivowels — are i and u. Y often serves as a weak vowel as well, functioning in the same way as i.
The basic rule of vowel combinations and syllables is that two strong vowels cannot be in the same syllable, so that when two strong vowels are next to each other, they are considered to belong to separate syllables. But other combinations — such as a strong and a weak vowel or two weak vowels — are considered to form a single syllable.
Important pronunciation note: In real life, especially in rapid speech, two strong vowels, such as in the words maestro and Oaxaca, often slide together in a way that may sound like a single syllable or very close to it. But they are still considered separate syllables for writing purposes, such as when dividing words at the end of a line or for the use of accent marks.
When a strong and a weak vowel or two weak vowels combine to form a single syllable, they form what is known as a diphthong. An example of a diphthong is the ai combination in baile. The ai combination here sounds much like the English word "eye." Another example is the ui combination in fui, which to the English speaker sounds much like "fwee."
In some words, a strong and weak vowel or two weak vowels don't merge together but instead form separate syllables. In those cases, a written accent over the weak vowel is used to show the distinction. A common example is the name María. Without the accent mark, the name would be pronounced much like MAHR-yah. In effect, the accent mark turns the i into a strong vowel. Other words where an accent mark is used to keep a weak vowel from becoming part of a diphthong include río, heroína, dúo and país.
If there is an accent over the strong vowel, it doesn't destroy the diphthong. For example, in adiós, the accent merely indicates where the spoken stress goes but doesn't affect how the vowels work together.
Occasionally, a diphthong can combine with a third vowel to form a triphthong. Triphthongs never have two strong vowels in them; they are formed by either three weak vowels or a strong vowel with two weak vowels. Words that have triphthongs include Uruguay, estudiáis and buey.
Note that for purposes of the written accent, the y is considered a consonant even if it is functioning as a vowel. Thus the final syllable of Uruguay is what gets the stress; that's where the stress goes on words ending in a consonant other than n or s. If the final vowel were an i, the word would need to be spelled Uruguái to maintain the pronunciation.