A method and apparatus for operating a ventilator to control the fraction of pressure inspired oxygen (FiO2) to a patient that includes: providing a ventilator controller that includes a software algorithm, a pulse oximeter and a FiO2 flow rate controller; measuring the pulse oximetry of the patient and computing an average pulse oximetry value over a time period; selecting a first, second and third pulse oximetry levels as set points for the ventilator controller; selecting an update time interval; decreasing the FiO2 flow rate by a first incremental amount when the average pulse oximetry value is greater than the first level; increasing the FiO2 flow rate by a second incremental amount when the average pulse oximetry value is less than the second level; increasing the FiO2 flow rate to the maximum and initiating an alarm condition when the average pulse oximetry value is less than the third level.