A method for maintaining a volume of a breathing gas in a desired level when ventilating a subject is disclosed herein. The method includes supplying the volume of the breathing gas for an inspiration and receiving the volume of the breathing gas for an expiration and withdrawing a gas sample from the volume of the breathing gas for an analysis. The method also includes providing a signal indicative of a volume of the gas sample withdrawn and determining the volume of the gas sample based on providing the signal. The method further includes controlling a volume of a compensation gas configured to be added into the breathing gas based on determining the volume of the gas sample for maintaining the breathing gas volume in the desired level. A corresponding arrangement for maintaining a volume of a breathing gas in a desired level is also provided.