A pulse-width modulation method for controlling oxygen concentration in an anesthetic machine or in a ventilator, comprising the following steps: step A, with a predetermined time interval as one pulse interval, a processing unit divides a breathing cycle into multiple consecutive pulse intervals step B, a data calculation unit calculates the average inspiratory flow in a certain time interval on the basis of inspiratory flows in one cycle that are detected by a detecting unit, and then calculates the average oxygen flow of this stage on the basis of the average inspiratory flow and, step C, a control unit selects a solenoid valve and controls the opening and closing times thereof on the basis of the average oxygen flow as calculated in the previous step to implement control of the oxygen flow for each interval.