Let f\colon A\to A be an idempotent on a set A. Let B be the subset {\mathopen {}\left \{f{\mathopen {}\left (a\right )\mathclose {}}\,\middle \vert \,a:A\right \}\mathclose {}}\subseteq A, sometimes called the direct image of f in A. Then f\colon A\to A factors, by definition, through some unique r\colon A \to B, where r{\mathopen {}\left (x\right )\mathclose {}} = f{\mathopen {}\left (x\right )\mathclose {}} for all x:A. We define s\colon B\to A to be be the subset inclusion.
We must check that r\circ s = \mathsf {id}_{B}; in other words, we fix b:B to check that r{\mathopen {}\left (s{\mathopen {}\left (b\right )\mathclose {}}\right )\mathclose {}} = b. By definition, the subset inclusion s\colon B\to A takes b to the corresponding element s{\mathopen {}\left (b\right )\mathclose {}}:A such that b=f{\mathopen {}\left (s{\mathopen {}\left (b\right )\mathclose {}}\right )\mathclose {}}. By definition of r\colon A \to B, we therefore have r{\mathopen {}\left (s{\mathopen {}\left (b\right )\mathclose {}}\right )\mathclose {}}=f{\mathopen {}\left (s{\mathopen {}\left (b\right )\mathclose {}}\right )\mathclose {}}=b.