sample size calculation for obtaining coin fairness Suppose that someone gives you a coin with some unknown weighting (maybe it's a fair coin, or maybe it's just 25% likely to get heads, or etc). How many times would you have to flip the coin to determine, within some confidence, the weighting of the coin (the probability the coin will get heads in general)?
Edit:
To clarify, I'm looking to see how the coin is loaded/weighted: for example, an "unloaded" coin would be weighted such that the probability of heads is 50%, whereas a "loaded" coin may have the heads probability at 70%, 90%, or etc. I want to know when I can stop flipping the coin with some level of confidence that the probability of heads is x% (where x% is calculated using the data, not assumed prior to having data).
Edit: 
To clarify further, I'll give an example: suppose I have some system that outputs a 0 or a 1 after each trial. After 5 trials, I end up with {01111}. So the two questions it raises are a) how do I find the probability that the next result is a 1, given only my 5 previous trials and b) how do I find the confidence of the calculation performed in a (based on the answers given so far, I'm guessing I can use a confidence as a stopping point, ie once a confidence level of 80% is reached I can stop doing more trials)?
Thank you in advance for your help.
 A: It is fairly well explained here:
https://en.wikipedia.org/wiki/Checking_whether_a_coin_is_fair
Basically, using the Bayesian inference method and assuming an uniform prior distribution, which is reasonable (it represents maximum initial uncertainty about the fairness of the coin), the posterior probability for the actual probability $r$ of obtaining heads in a single toss after having observed $h$ number of heads and $t$ number of tails (therefore $n=h+t$ is the total number of tosses) is a Beta distribution with parameters $\alpha=h+1$ and $\beta=t+1$
$$f(r|H=h,T=t)=\frac{(h+t+1)!}{h!t!}r^h(1-r)^t$$
This will give you an idea of how r is distributed. The maximum-a-posteriori estimate (mode) is
$$r^*(h,t)=\frac{h}{h+t}$$
And the expected value is
$$E[r](h,t)=\frac{h+1}{h+t+2}$$
One can use the standard deviation as estimation of the uncertainty
$$\sigma(h,t)=\sqrt{\frac{(h+1)(t+1)}{(h+t+2)^2(h+t+3)}}$$
As you can see it doesn't depend just on the total number of tosses $h+t$ but also on $h$, so the criterion for a given confidence interval will be different depending on the sequence of results of the tosses.
