The ears are being blocked because of the sudden pressure difference between the outer and middle ear. When we say middle, we mean from the eardrum of our ear and inside, while when we say outer, we mean from the eardrum and out.
The eardrum works like a fence between the inside and the outside. Now if the external pressure suddenly increases or decreases, as happens when we change altitude, then the eardrum will stretch to the side with the least pressure. For example, as we descent (e.g. on an airplane) and air pressure of the atmosphere increases, the air pressure in the middle ear will be smaller and will cause the eardrum to stretch inwards. This extension not only causes the discomfort that you feel before your ears pop, but also there is a reduction in hearing because the pressure on the eardrums makes the sound more difficult to transmit.
For the body to bring back the eardrum to its normal state, it must increase (or reduce) the internal pressure accordingly. Your body can equalize the pressure between your middle ear and the atmosphere, allowing the air to enter your middle ear through the Eustachian tube (a small tube connecting the middle ears to the throat, one on each side). These tubes are normally closed, but when such a situation arises, they open and thus balance the internal pressure with the external pressure. When they open up, you feel the balance of pressure and you hear the change because it’s happening in your ear. This equation of pressure is what you feel as a “pop”. If you have a nasal congestion (e.g. due to a cold), the tubes can be blocked and this makes the pressure equalization more difficult.
When we swallow or yawn, we help the work of these tubes because the muscles that open the Eustachian tubes are activated, which is why we hear a “click” sound in our ear. That’s why chewing (e.g. a gum) when changing altitude helps to keep our ears unblocked!