The present invention provides a gas generator including an electrolytic device, a gas pathway, and a three-way valve module. The electrolytic device is configured for electrolyzing electrolyzed water to generate gas with hydrogen. The gas generated from the electrolytic device is transferred by the gas pathway for inhaling. The three-way valve module is configured on the electrolytic device for balancing a pressure in the electrolytic device by importing an ambient gas. The present invention uses the three-way valve module to balance the pressure in the electrolytic device for maintaining the water level of the electrolyzed water, thereby avoiding the electrolyzed water splashing or corroding the other elements.