TITLE: If the product of two idempotents is idempotent, must the two idempotents commute?
QUESTION [8 upvotes]: It is a basic fact that when two idempotents $e,f$ in a semigroup $S$ commute, then $ef$ is an idempotent. Is the converse true? Is it true for idempotents in rings?

REPLY [9 votes]: No. In $M_2(\mathbb{C})$, let 
$$
e=\begin{bmatrix}1&0\\ 0&0\end{bmatrix}, \ \ 
f=\begin{bmatrix}1&1\\ 0&0\end{bmatrix}.
$$
So 
$$
e^2=e, \ \ f^2=f, \ \ ef=f, \ \ fe=e.
$$

REPLY [3 votes]: Consider the semi-group of matrix $2\times 2$ with real entries and $A:=\pmatrix{0&1\\\ 0& 1}$, $B=\pmatrix{1&0\\\ 0&0}$. Then $A^2=A$, $B^2=B$, $AB=0$ but $BA=\pmatrix{0&1\\\ 0&0}\neq AB$.