A gearbox converts the rotational energy of the engine to a rotational speed appropriate for the wheels. Mechanical gearboxes do so with simple gears. Automatic gearboxes use more complicated planetary gearsets.
A car's engine cannot be attached directly to the wheels. Car engines can only operate in a relatively small RPM band, and the top speed they could achieve in this band is fairly low. Gearboxes change the ratio between the engine's rotational speed and the rotational speed of the wheels. At low speeds, cars rely on small gears. At higher speeds, larger gears are needed.
Manual gearboxes require the driver to select manually which gear to use. Automatic gearboxes, on the other hand, change to new gears automatically. When the engine's speed drops in an automatic car, its gearing is being changed. Traditionally, manual gearboxes were significantly more efficient than automatic gearboxes. Modern automatic gearboxes are far more efficient.
Some new cars rely on continuously variable transmissions, which move a belt or chain along a cone to deliver the ideal gearing ratio at all times. Electric cars do not need gearboxes since electric motors can operate in a wide RPM range, and in-wheel motors that do not need different gears are expected to come to the market in coming years.