Based on a level of significance 'α', and a Type II error 'β' at a departure 'δ' from the target mean, the formula for the ttest (small sample sizes) is:
where:
t_{α} the t statistic corresponding to the chosen level of significance (use t_{α/2} for two sided tests)
t_{β} the t statistic corresponding to the Type II error (use for both one and two sided tests)
Note that:
The formula for the z test (large sample size) is essentially the same. For large sample sizes the t statistic converges to the z statistic:
z_{α} the z statistic corresponding to the chosen level of significance (use z_{α/2} for two sided tests)
z_{Β} the z statistic corresponding to the Type II error (use for both one and two sided tests)

for two sided tests use α/2, but still use β (NOT β/2)

the standard deviation must be known to use either formula, although a reasonable estimate will serve

because the tstatistic depends on the number of degrees of freedom (n1) the equation is solved iteratively. Start with the zstatistic and find an approximation for 'n' (or guess n). Use this value of 'n' to find the t statistic and recalculate to get a better approximation for 'n'. Repeat until the values converge.
