Confidence interval for estimating probability of a biased coin Suppose we have a coin with an unknown probability $p$ of coming up heads and that of $1-p$ of coming up tails. 
Now, we repeatedly flip the coin $n$ times and record the results, heads turn up $X$ time, then we could estimate $p$ with $\hat p = X/n$.
The problem is how close $\hat p$ is to $p$. For example, if we already know $0.4≤p≤0.6$, to obtain an estimate of $\hat p$ that is within $5\%$ of the real $p$, i.e.
$$0.95p \le \hat p \le 1.05 p$$
how large does $n$ need to be if we want to ensure the probability the above confidence interval is at least 0.95? i.e.
$$\mathbb{P}[0.95p \le \hat p \le 1.05p] \ge 0.95$$
 A: Let $X_i$ be $1$ if the $i$-th flip is a head and $X_i = 0$ if the $i$-th flip is a tail. 
The $X_i$'s are i.i.d. $\text{Bernoulli}(p)$. Hence, $E[X_i] = p$ and $\text{Var}[X_i] = p(1-p)$. 
Our estimate for $p$ is given by $\hat{p} = \dfrac{1}{n}\displaystyle\sum_{i = 1}^{n}X_i$. 
By linearity, $E[\hat{p}] = p$, and since the $X_i$'s are i.i.d., we get that $\text{Var}[\hat{p}] = \dfrac{p(1-p)}{n}$. 
For large $n$, the distribution of $\hat{p}$ can be approximated by a normal distribution with mean $p$ and standard deviation $\sqrt{\dfrac{p(1-p)}{n}}$.
Therefore, $\Pr[|p-\hat{p}| < 0.05p] \approx \Pr\left[-0.05\sqrt{\dfrac{np}{1-p}} < Z < 0.05\sqrt{\dfrac{np}{1-p}}\right]$, where $Z \sim N(0,1)$. 
You can calculate this in terms of the normal cdf. 
A: Continuing JimmyK4542's answer, the probability of the interval is still a function of $n$, and $p$, so I plotted the probability as a function of $n$ (how many tosses) for different possible $p$ between 0.4 and 0.6, we could see that to ensure the inequality in the question holds, $n$ > 2300.
In general, the smaller the $p$ is, the larger the $n$ needs to be to ensure $\text{Pr}(|p - \hat p| < 0.05p)$, which makes sense as e.g. $0.05 \cdot 0.1 = 0.005$, which is much smaller a cutoff than $0.05 \cdot 0.9 = 0.045$.
Instead, it may be more useful to constrain by $\text{Pr}(|p - \hat p| < c)$, which c is a constant cutoff, e.g. 0.01, i.e. the real $p$ and estimated $\hat p$ only differ by 0.01 at max.

An zoom out version of the plot

Plotting code:
import matplotlib
import matplotlib.pyplot as plt

matplotlib.style.use('classic')

import numpy as np
import scipy.stats as stats

def cdf(n, p):
    factor = np.sqrt(n * p / (1 - p))
    return stats.norm.cdf(0.05 * factor) - stats.norm.cdf(-0.05 * factor)

ns = np.arange(1, 3000)
ps = np.arange(0.4, 0.61, 0.05)
for p in ps:
    plt.plot(ns, cdf(ns, p), label=f'p={p:.2f}')

plt.plot(ns, np.repeat(0.95, ns.shape[0]), color='black')
plt.legend(loc='best')
plt.grid()
plt.ylabel('Pr')
plt.xlabel('n')

