This is typically carried out before an experiment, and in such cases is called as a priori power analysis.
On the other hand, sometimes a statistical power analysis is carried out after data has been collected, in which case it is called a post hoc power analysis and it determines the power in the study.
More technically, statistical power is the probability that a statistical analysis will be able to catch false null hypotheses. This is another way of saying that the analysis will not make a Type-II error.
In general, the larger the sample size, the higher statistical power in the analysis. However, we would not like to have a very large sample size because it involves costs in terms of time, effort and other resources.
Therefore using a statistical power analysis, we compute beforehand what an optimal sample size would be that makes sure the analysis is powerful and also keeps the sample size as small as possible.
The power of a statistical analysis also depends on the null hypothesis itself. If the null hypothesis is wrong by a wide margin, it will be easy to catch and therefore such an analysis will be much more powerful.
For example, suppose an experimenter claims that tying a subject's hands to the back will not affect his running speed. This null hypothesis is simple to disprove and therefore the statistical analysis will be powerful.
On the other hand, if a researcher claims that running direction (clockwise or anticlockwise) around the track does not have any effect on the runner speed, then it is not an easy task to disprove it, and the analysis will most likely be less powerful.
The power of a statistical analysis depends on the hypothesis and is not simply a property of a statistical experiment.
Also, different statistical tests have different power which is an inherent difference between different statistical analyses.
An a priori power analysis is thus required for each hypothesis which is going to be tested by the experimenter in order to determine the optimal sample size.