A numerical model is presented to describe the electron beam neutralization during long-pulse and continuous-wave operation in gyrotrons. This model has been implemented in the electrostatic, self-consistent electron optics code Ariadne. Using this model, the electron beam parameters in the cavity could be determined as a function of the level of neutralization. The electron beam was shown to be partially neutralized in the cavity, and the effect of neutralization on the beam properties was investigated for a cylindrical gyrotron. This study was extended to a coaxial cavity gyrotron, identifying two ion trapping regimes, which only had a minor impact on the beam parameters.