Hydraulic machines are faced with increasingly severe performance requirements. The need to design smaller and more powerful machines rotating at higher speeds in order to provide increasing efficiencies has to face a major limitation: cavitation. The problem is inherently three-dimensional, due to the axial clearances, the relief and circumferential grooves, and to the circular pipes through which the fluid enters and exits the pump. A simplified two-dimensional numerical approach by means of computational fluid dynamics (CFD) has been developed for studying the effect of cavitation in the volumetric efficiency of external gear pumps. The assumptions employed prevent from predicting realistic values of the volumetric efficiency, but show to be valid to understand the complex flow patterns that take place inside the pump and to study the influence of cavitation on volumetric efficiency. A method for simulating the contact between solid boundaries by imposing changes in viscosity has been developed. Experiments of unsteady cavitation in water and oil performed by other authors have been numerically reproduced using different cavitation models in order to select the most appropriate one and to adjust its parameters. The influence of the rotational speed of the pump has been analyzed. Cavitation in the suction chamber very effectively damps the water hammer associated to the sudden change of the contact point position at the end of the gearing cycle. At high rotational speeds, the volume of air becomes more stable, reducing the flow irregularity. When cavitation takes place at the meshing region downstream from the contact point, the volume of air that appears acts as a virtual second contact point, increasing the volumetric efficiency of the pump.