The air pressure outside of your body changes as altitude changes. This creates a difference in pressure on the two sides of the eardrum. The result is a feeling of pressure and blockage in the ears.
Yawning or swallowing usually opens the Eustachian tube, which connects the middle ear to the nose. These movements allow the pressure to equalize in the ears. Performing them can unclog blocked ears when you are going up or coming down from high altitudes. Chewing gum the entire time you are changing altitudes helps by causing you to swallow frequently. This may prevent you from getting blocked ears in the first place.
People who always have blocked ears when flying may consider taking a decongestant about an hour before the flight leaves.
If your ears are blocked, try breathing in, then gently breathing out while holding your nostrils and mouth closed. If you do this too forcefully, you can cause ear infections by forcing bacteria into your ear canals. A perforation (hole) in your eardrum can result if you blow too hard. See: Barotrauma
High altitudes and blocked ears; Flying and blocked ears; Eustachian tube dysfunction -high altitude