The act of yawning is to increase oxygen intake. You often yawn when your tired because your breaths get more shallow and yawning increases the air intake and therefore ups the oxygen giving you a short period of time of increased awareness. ;)
Yawning is for several times to cool off your brain as oxygen enters and cools it off. Yawning is instictive as well, which is known as stretching (during a yawn) as all animals do this tipe of yawn, the person will stretch all of the important limbs for it to be alert and "on its toes" in case of a predatorial attack. Which leads to its contageousness. Studies show that yawnig is more contageus between family, then friends, then aquaintances respectively. It is noticable is herds of deer that they will stretch and pass it on through the herd due to such contageousness as so to leave the entire herd alert and stretched in case of an attack.