This paper presents sample size calculations for testing the mediation of the effect of a primary predictor by an intermediate variable. This problem is related to validating surrogate markers and to testing the effect of a primary predictor in the presence of confounders. For those problems, proposals for sample size calculation exist in the literature and can be adapted to the problem of mediation. Methods based on the variance inflation factor in linear regression provide exact sample size calculations for the linear model and approximations for the logistic, Poisson, and Cox models. We propose another procedure based on simulation of the underlying data structure, with applications to the logistic and Cox models. For the Poisson model, a new analytic method is also proposed. The behavior of the different proposals is investigated by means of simulation studies.