When you yawn or swallow, the eustachian tubes open briefly and make the air pressure equal inside and outside the ears (top picture).
Also, the eustachian tubes drain fluid from the ears. But if a tube can't open, fluid can get trapped in the middle ear (bottom picture). This creates pressure that can cause ear pain.
eMedicineHealth Medical Reference from Healthwise
To learn more visit Healthwise.org