# When $HK$ is a subgroup why $KH \subseteq HK$?

Here is the text from the book Abstract Algebra by Dummit and Foote :

Proposition 14. If $H$ and $K$ are subgroups of a group, $HK$ is a subgroup if and only if $HK=KH$.

Proof: Assume first that $HK=KH$ and let $a,b\in HK$. We prove $ab^{-1}\in HK$ so $HK$ is a subgroup by the subgroup criterion. Let $$a=h_1k_1\ \ \ \ \ \ \text{and}\ \ \ \ \ \ b=h_2k_2,$$ for some $h_1,h_2\in H$ and $k_1,k_2\in K$. Thus $b^{-1}=k_2^{-1}h_2^{-1}$, so $ab^{-1}=h_1k_1k_2^{-1}h_2^{-1}$. Let $k_3=k_1k_2^{-1}\in K$ and $h_3=h_2^{-1}$. Thus $ab ^{-1}=h_1k_3h_3$. Since $HK=KH$, $$k_3h_3=h_4k_4,\ \ \ \ \ \ \text{for some }h_4\in H,\ \ \ \ k_4\in K.$$ Thus $ab^{-1}=h_1h_4k_4$, and since $h_1h_4\in H$, $k_4\in K$, we obtain $ab ^{-1}\in HK$, as desired.

Conversely, assume that $HK$ is a subgroup of $G$. Since $K\leq HK$ and $H\leq HK$, $\color{red}{\displaystyle\underline{\color{black}{\text{by the closure property of subgroups, }KH\subseteq HK}}}$. To show the reverse containment let $hk\in HK$. Since $HK$ is assumed to be a subgroup, write $hk=a^{-1}$, for some $a\in HK$. If $a=h_1k_1$, then $$hk=(h_1k_1)^{-1}=k_1^{-1}h_1^{-1}\in KH,$$ completing the proof.

How $KH \subseteq HK$?! Well of course a (sub)group is closed under its operation, but here is talking about two distinct subgroups and I don't understand the underlined claim at all.

It follows by the above line. If $H \le HK$, then for all $h \in H$, $h \in HK$ (namely by taking $he \in HK$). Similarly, for all $k \in K$, $k \in HK$ (by taking $ek \in HK$).

So since $h \in HK$ for all $h \in H$ and $k \in HK$ for all $k \in K$, and since $HK$ is a group, we have $kh \in HK$ for all $k \in K$ and $h \in H$. So $KH \subset HK$ by definition of $KH$.