The paper is focused on the development of a thermodynamic mathematical model describing the internal ballistic phenomena, taking place within working chambers of an airgun. The objective is to derive a governing equation modeling the change of gas temperature in a control volume subsuming several incoming and outgoing mass airflow rates. A novel algorithm for solving internal ballistics of all types of airguns is also developed and applied for the case of spring-piston airgun. The mathematical model and solving algorithm are validated and verified experimentally.