Your ears pop when you rise in elevation (like when you are in an airplane that is gaining altitude) because of the changing air pressure and the difference between the outside air pressure and the air pressure within your ear.
As you gain elevation, the air gets thinner and air pressure drops. But inside your ear, the air is still at the pressure that you came from. That pushes your eardrum out and causes discomfort.
If you are able to get some of the air inside your ear to escape via your Eustachian Tubes, the pressure equalizes, and your eardrum "pops" back to its original position.
Air pressure is the force exerted on us by the weight of tiny particles of air. Although air molecules are invisible, they still have weight and take up space. If you've ever been to the top of a tall mountain, you may have noticed that your ears pop and you need to breathe more often than when you're at sea level.
As the number of molecules of air around you decreases, the air pressure decreases. This causes your ears to pop in order to balance the pressure between the outside and inside of your ear. Since you are breathing fewer molecules of oxygen, you need to breathe faster to bring the few molecules there are into your lungs to make up for the deficit. As you climb higher, air temperature decreases. Typically, air temperatures decrease about 3.6° F per 1,000 feet of elevation.