An external gear motor consists of two gears, the driven gear – attached to the output shaft by way of a key, etc. – and the idler gear.
High pressure oil is ported into one side of the gears, where it flows around the periphery of the gears, between the gear tips and the wall housings in which it resides, to the outlet port. The gears then mesh, not allowing the oil from the outlet side to flow back to the inlet side.
For lubrication, the gear motor uses a small amount of oil from the pressurized side of the gears, bleeds this through the (typically) hydrodynamic bearings, and vents the same oil either to the low pressure side of the gears, or through a dedicated drain port on the motor housing, which is usually connected to a line that vents the motor’s case pressure to the system’s reservoir.
An especially positive attribute of the gear motor is that catastrophic breakdown is less common than in most other types of hydraulic motors. This is because the gears gradually wear down the housing and/or main bushings, reducing the volumetric efficiency of the motor gradually until it is all but useless. This often happens long before wear causes the unit to seize or break down.