We flip a coin 20 times and observe 12 heads. What is the probability that the coin is fair? im having some trouble getting around this. A little explanation would be really helpful. 
 A: You appear to be using a Beta(1,1) prior on $\theta$. Since this is a continuous distribution, the prior (and posterior) probability of the event that the coin is exactly fair, $\theta=1/2$, is zero.  
What would perhaps be a more sensible prior (see Lindley 1957 pp. 188-189 for a discussion of similar examples) would be a point mass at $\theta=1/2$ given the event $H_0$ that the coin is fair and $\theta\sim \mbox{Beta}(\alpha,\beta)$ given an unfair coin (the event $H_1$) and some prior probabilities $q$ and $1-q$ that $H_0$ and $H_1$ are true respectively.
The probabilities of observing $X=x$ heads out of $n$ coin flips under each hypothesis would then be,
\begin{align}
P(X=x|H_1)&=\int_0^1 P(X=x|\theta,H_1)f_{\theta|H_1}(\theta)d\theta
\\&=\frac{n!}{x!(n-x)!B(\alpha,\beta)}\int_0^1 \theta^{x+\alpha-1}(1-\theta)^{n-x+\beta-1}d\theta
\\&=\frac{n!B(x+\alpha,n-x+\beta)}{x!(n-x)!B(\alpha,\beta)},
\end{align}
and
$$
P(X=x|H_0)=\frac{n!}{x!(n-x)!2^n}.
$$
Using Bayes theorem, the posterior probability of $H_0$ would be
\begin{align}
P(H_0|X=x)
  &=\frac{P(X=x|H_0)P(H_0)}{P(X=x|H_0)P(H_0)+P(X=x|H_1)P(H_1)}
\\&=\frac{q}{q  + 2^n(1-q)B(x+\alpha,n-x+\beta)/B(\alpha,\beta)}
\end{align}
instead of zero.
The Figure below shows typical realisations of this posterior probability for increasing sample sizes $n$ for a Beta(1,1) prior and $q=0.5$.  For a truly fair coin ($\theta=1/2$, blue curve), the posterior probability of $H_0$ tends to 1 as expected.  If the coin is slightly unfair ($\theta=0.55$, red curve) the hypothesis that the coin is fair appear more likely initially until the evidence against $H_0$ eventually becomes overwhelming.

