On a normal day on land, the air pressure on both sides of your eardrum is equal, with air passing easily through the Eustachian tube, a narrow tube lined with membranes that connects the back of the nose to the middle ear.
Air have low density as we go higher altitude. Up in the air, even though you’re in a pressurized cabin, the air pressure quickly becomes unequal. The difference in pressure causes the ear drum to be stretched a little and you start to feel the pain.
Since the Eustachian tube is narrow, it takes some time for the air from the back of the nose to enter through it and equalize the pressure that causes pain in the ear drum.
When you fly in a plane, your ears may pop as the air inside them expands. If this did not happen, your eardrum would burst as the air trapped inside your ear expanded.