Particle production in high-energy collisions is often addressed within the framework of the thermal (statistical) model. We present a method to calculate the canonical partition function for the hadron resonance gas with exact conservation of the baryon number, strangeness, electric charge, charmness and bottomness. We derive an analytical expression for the partition function which is represented as series of Bessel functions. Our results can be used directly to analyze particle production yields in elementary and in heavy ion collisions. We also quantify the importance of quantum statistics in the calculations of the light particle multiplicities in the canonical thermal model of the hadron resonance gas.