1.The answer to your specific question can be found in the Wikipedia page:
http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
Basically, as stated inThe idea of estimating a distribution parameter is to construct a random variable whose expectation is the questionparameter needed to be estimated. In your example, one associates a confidence intervalwe want to an estimate the success probability of a Bernoulli distribution parameterand we construct a binomially distributed random variable by repeated trials. The key point is that the new random variable has the same average (after normalizing by n) but its standard deviation is smaller (by a factor of sqrt(n)) which gives better bounds on the estimated value. The confidence level is just a percetile of the distribution of the random variable used for the estimation (in your example you chose 50%).The interval size is a function of the percentile which was required to be 50% in the question. The estimated value p* = k/n is inside the interval but the interval is not symmetric in general around this value. In the Wikipedia page, several approximations for large n are given, based on the central limit theorem, which are usually used in real-life estimations.
2.The above solution assumes prior knowledge that the distribution of a single trial is binomialBernoulli and that the trials are independent. Usually, one needs some prior knowledge to infere a statistical parameter. Specifically in your question, when the distrbution is not binomial, prior knowldge would be that the coin flips are independent, or that at after some flip the proportion coefficientsuccess probability p had changed, etc.