A computational method for the calculation of the solubility of gases, including argon, hydrogen, nitrogen, carbon dioxide, methane, and propane, in polystyrene over a wide range of temperatures and pressures is described. The excess chemical potentials and the partial molar volumes of gases in polystyrene were calculated using Widom's test-particle insertion method. Using the calculated chemical potentials and partial molar volumes of the sorbed gases at a fixed temperature, the chemical potentials in the polymer phase were expanded in terms of the pressure. Performing a grand-canonical ensemble molecular dynamics simulation of the gas phase, we calculated the phase coexistence point using a recent method by Vrabec and Hasse [Mol. Phys. 2002, 100, 3375-3383]. The results on the calculated solubility coefficients and solubilities over a wide range of temperatures and pressures are compared with experimental data.