Finding the $2\sigma$ confidence interval for a coin flip with unknown $p$ Suppose I have a hypothetical coin flip experiment where the probability $p$ of getting head in a single throw is unknown and can be anywhere such that $0 < p < 1$. I do have a random sample with $n$ flips and $x$ successes (heads). Flips are known to be independent of each other and the sample is assumed to be free of bias.
Obviously the best estimation for $p$ is $p = \frac{x}{n}$.
What I do want to find is a confidence interval $(p1, p2)$ so that $x$ is in the $2\sigma$ interval (or any arbitrary interval for that matter) of any $p \in (p1, p2)$ for $n$ tries.
How would I go about this? Is there an easy formula I can just plug $n$ and $x$ into?
I suppose I could do a binary search for $p1$ and $p2$ where I calculate the probability of getting  at least/most $x$ heads in $n$ tries and repeat that until I find a $p1$/$p2$ that is "close enough" to the desired confidence interval, but that does not feel right. Is suppose I'm asking whether there is a closed form formula for this.
Sidenote: My statistics knowledge and research abilities have forsaken me on this. It feels like the most basic question in statistics, yet I could not find a satisfying answer. I'm probably lacking the keywords for this or misunderstood examples I came across.

Would, e.g., the Clopper–Pearson method for confidence intervals work for you ?
The calculation is relatively accessible.
The following can be run in R, or at rdrr.io/snippets/.
The estimate is x/n, and the confidence interval is the Clopper–Pearson confidence interval for this proportion.
 x =  7
 n = 21
 binom.test(x, n, conf.level=0.95)


### number of successes = 7, number of trials = 21
###
### 95 percent confidence interval:
###    0.1458769 0.5696755
###
### sample estimates:
### probability of success 
###      0.3333333 

Some other potential methods are listed here, under Details: www.rdocumentation.org/packages/DescTools/versions/0.99.44/topics/BinomCI

"wald", "wilson", "wilsoncc", "agresti-coull", "jeffreys", "modified
wilson", "modified jeffreys", "clopper-pearson", "arcsine", "logit",
"witting", "pratt", "midp", "lik", "blaker"

