How does an Internal Gear Hub (IGH) work?

Internal gear hubs can usually shift gears at the pedaling frequency, so gears can be switched smoothly even during riding, reducing interference with riding.