The present invention relates to a method of delivering gas during ventilation of a patient using a system for breath delivery. The method of gas delivery includes real-time compensation of gas compression losses, in the current breath delivery phase, and gas leakage losses. The present invention further relates to a system for breath delivery. Still further, the present invention relates to a computer implemented method adapted of delivering gas during ventilation of a patient using a system for breath delivery.