If you have ever stuck your finger into your ear, you know about the ear canal. The ear canal is a tube, and at the end of the tube is the ear drum -- a thin piece of skin stretched tight like a drum over the end of the ear canal. You've probably read on a box of cotton swabs (or heard from your mother) that you should never stick anything in your ear. What you want to avoid is sticking something in that could puncture the ear drum.
On the other side of the ear drum is a hollow space filled with air, called the middle ear (see this page for a nice illustration). What you want is for the air in your ear canal and the air in the middle ear to have the same pressure. If they do, then the eardrum has equal pressure on both sides and it is smooth and happy. In order for the middle ear to equalize its pressure, there is a thin tube called the Eustachian tube that connects the middle ear's air chamber to the throat. Air can flow back and forth through the tube, and this keeps the air pressure in the middle air equal with the outside air pressure.
When you swim in deep water, there can be a lot of water pressure. At sea level, the air's pressure is 14.7 pounds per square inch (PSI). Each foot of water creates water pressure of 0.43 PSI. So if you swim in 10 feet of water, the total water pressure is 4.3 PSI. Add that to the air pressure of 14.7 and the total pressure at the bottom of the deep end is 19 PSI.
If your Eustachian tube is clogged or narrowed for any reason, then your middle ear gets shut off and becomes a closed chamber. It holds air at 14.7 PSI. When you swim to the bottom of the deep end, the water is pressing into the ear canal at 19 PSI, so the ear drum bows inward because of the pressure difference. Since the ear drum is full of nerves, you feel this bowing as pain.
To solve the problem, you can equalize the pressure. When you start to feel pain in your ears, hold your nose shut with your fingers and blow into your nose. You will hear your ears pop and the pain should go away. By blowing, you increase the air pressure in your lungs and throat, and it blows the air up your Eustachian tube into the middle ear to equalize the pressure. When you rise back up to the surface, the middle ear will contain excess pressure, but the Eustachian tube generally releases it automatically. If not, try yawning to open up the Eustachian tubes.
The same sort of pressure difference can arise as you go up or down in a tall building on a fast elevator, or as you ascend or descend in a small plane. On ascent, your Eustachian tubes generally equalize the pressure automatically, and on descent you can try the blowing technique, yawning or chewing gum.
These links will help you learn more: