The purpose of this paper is to study the effect of chemical heat treatments on cavitation erosion resistance of the 304 stainless steel. Three types of diffusion layers are prepared on the 304 stainless steel using gas nitriding, gas carburizing, and carbonitriding treatments. Phase composition and surface microstructure of the diffusion layers are characterized by X-ray diffraction and scanning electron microscopy. And then, the cavitation erosion behavior of the diffusion layers are tested and compared with the one of the 304 stainless steel. The cavitation test is performed in an ultrasonic vibration system integrated with an electrochemical workstation. The mass loss, scanning electron microscopic morphology, and electrochemical test are adopted to assess the surface damage of the diffusion layers. A measurement for the mechanical properties of the diffusion layers shows that the hardness and the elastic modulus of the gas nitrided diffusion layer, carbonitrided diffusion layer, carburized diffusion layer, and 304 stainless steel are 5.3 GPa and 260 GPa, 4.2 GPa and 236 GPa, 4.0 GPa and 210 GPa, 2.5 GPa and 193 GPa, respectively. A cavitation erosion test of 14 h shows that mass loss of the gas nitrided diffusion layer, carbonitrided diffusion layer, carburized diffusion layer, and 304 stainless steel is 5.19 mg, 8.97 mg, 14.37 mg, and 6.62 mg, respectively. The electrochemical test results also indicate that the gas nitrided diffusion layer has a higher corrosion resistance than the carburized diffusion layer, carbonitrided diffusion layer, and stainless steel under cavitation erosion condition. As a conclusion, the gas nitrided diffusion layer is capable of enhancing the cavitation erosion resistance of the stainless steel, while the carburized diffusion layer and carbonitrided diffusion layer increases the mass loss of the stainless steel under cavitation erosion condition.