Why is $\frac 25$ the real part of $\frac{1}{2+i}$? According to Wolfram Alpha, Re(1/(2+i))=2/5.  
How did it calculate that?

Multiply numerator and denominator by $2-i$:
$$\frac 1{2+i}\cdot \frac{2-i}{2-i} = \frac{2-i}{4-(-1)} = \frac{2-i}{5} = \frac 25 - \frac 15\cdot i$$
Edit for more explanation as to why this strategy works. 
We multiply numerator and denominator by the conjugate of $2+ i$, which is $2+i$, to remove the imaginary number from the denominator. Doing so gives us a real-valued  denominator: $$(2 + i)(2-i) = 2^2 - (i^2) = 4 - (-1) = 5.$$ Having multiplied by $\frac{2-i}{2-i}=1$, that transforms the numerator to $1\cdot (2-i) = 2- i$. Then all that remained was to transform the fraction $\dfrac{2-i}{5}$ into its real and imaginary components.
The same strategy works for any fraction of the form $\dfrac{z_1}{z_2},\,$ where $z_1, z_2 \in \mathbb C$ and $z_2 = a + bi$ where $a, b \in \mathbb R, b\neq 0$. We simply multiply numerator and denominator by $\overline{z_2}$. The denominator is then $z_2\cdot \overline{z_2} = |z| = a^2 + b^2$
