Solution 1:

Let's look at three related concepts, in increasing order of complexity:

  1. Direct products. We say that $G$ is (isomorphic to) a direct product of $M$ and $N$ if and only if there exist subgroups $H$ and $K$ of $G$ such that:

    • $H\cong M$ and $K\cong N$;
    • $H\triangleleft G$ and $K\triangleleft G$;
    • $H\cap K=\{e\}$;
    • $G=HK$.
  2. Semidirect products. We say that $G$ is (isomorphic to) a semidirect product of $M$ by $N$ if and only if there exist subgroups $H$ and $K$ of $G$ such that:

    • $H\cong M$ and $K\cong N$;
    • $H\triangleleft G$;
    • $H\cap K=\{e\}$;
    • $G=HK$.
  3. Extensions. We say that $G$ is (isomorphic to) an extension of $M$ by $N$ if and only if there exists a subgroup $H$ of $G$ such that

    • $H\cong M$;
    • $H\triangleleft G$;
    • $G/H\cong N$.

1 and 2 look very similar. In fact, 1 is a special case of 2 (when $K$ is normal); and 2 is a special case of 3: if $G=HK$, $H\triangleleft G$, and $H\cap K=\{e\}$, then $K$ maps isomorphically onto $G/H$ via the natural projection (the intersection with the kernel is trivial, so the projection restricted to $K$ is one-to-one; and every element of $G$ can be written as $x=hk$ with $h\in H$ and $k\in K$, so $Hx = Hk$, hence the map is onto when restricted to $K$).

But each one is a more general construction than the previous one, yielding more general types of groups.

For instance, in Direct Products, the conditions immediately imply that elements of $H$ commute with elements of $K$:

Lemma. Let $G$ be a group, and let $H$ and $K$ be normal subgroups of $G$. If $H\cap K=\{e\}$, then $hk=kh$ for all $h\in H$ and $k\in K$.

Proof. Consider $hkh^{-1}k^{-1}$. Since $K$ is normal in $G$, then $$hkh^{-1}k^{-1} = (hkh^{-1})k^{-1} \in (hKh^{-1})K = KK = K;$$ and since $H$ is normal in $G$, then $$hkh^{-1}k^{-1} = h(kh^{-1}k^{-1}) \in H(kHk^{-1}) = HH = H.$$ Therefore, $hkh^{-1}k^{-1}\in H\cap K = \{e\}$, so $hkh^{-1}k^{-1}=e$. Multiplying on the right by $kh$ gives $hk=kh$, as desired. $\Box$

So, for example, if all you know are direct abelian groups, then direct products will only give you abelian groups. If both $M$ and $N$ have exponent $k$, then direct products will give you a group of exponent $k$. (In fact, any identity satisfied by both $M$ and $N$ will be satisfied by $M\times N$; but this is perhaps a little advanced for you right now, so don't worry too much about it).

By contrast, semidirect products are more complicated, because that second subgroup doesn't have to be normal. The argument above is invalid, and we don't always get that elements of $H$ and elements of $K$ commute (if they do, then you have a direct product). The smallest example is $S_3$, the nonabelian group of order $6$ viewed as the permutations of $\{1,2,3\}$, with $M=C_3$, the cyclic group of order $3$, $N=C_2$, the cyclic group of order $2$, and $H=\{I, (1,2,3), (1,3,2)\}$, $K = \{I, (1,2)\}$ (other choices of $K$ are possible).

In a semidirect product, the fact that $H$ is normal means that for every $k\in K$ you have $kHk^{-1}=H$; that is, each $k$ induces an automorphism of $H$. So we can define a homomorphism $K\to \mathrm{Aut}(H)$, by letting $k$ map to the homomorphism $h\mapsto khk^{-1}$. If this map is trivial, you get the direct product of $H$ and $K$. If the map is not trivial, then you get more interesting groups. Different homomorphisms may lead to nonisomorphic groups, so that now we have to be careful: while there is one and only one way to construct a "direct product" of two groups $M$ and $N$, there may, in general, be many (non-equivalent) ways of constructing semidirect products of $M$ by $N$.

Note that it is now possible to have a semidirect product of abelian groups that is not abelian (as in the $S_3$ example). And it is no longer true that if both $M$ and $N$ are of exponent $k$, then a semidirect product will also have exponent $k$. For example, take $M=C_2\times C_2 = \{1,x\}\times\{1,x\}$, which is of exponent $2$, take $N=\{1,n\} = C_2$, also of exponent $2$, and let the nontrivial element of $N$ act on $M$ by the rule $n^{-1}(a,b)n = (b,a)$. Then $(x,1)n$ has order $4$: $$\begin{align*} \bigl((x,1)n\bigr)^2 = (x,1)n(x,1)n &= (x,1)(n^{-1}(x,1)n) = (x,1)(1,x) = (x,x)\\ \bigl((x,1)n\bigr)^3 = (x,x)(x,1)n &= (1,x)n\\ \bigl((x,1)n\bigr)^4 = (1,x)n(x,1)n &= (1,x)(n^{-1}(x,1)n) = (1,x)(1,x) = (1,1). \end{align*}$$

Extensions are even more complex: in essence, every finite group can be viewed as a sequence of extensions of simple groups (hence, in part, the interest in classifying all finite simple groups). Not every extension is a semidirect product (or a direct product). For example, $\mathbb{Z}_4$, the cyclic group of order $4$, is an extension of $\mathbb{Z}_2$ by $\mathbb{Z}_2$: the subgroup $H=\{\overline{0},\overline{2}\}$ is cyclic of order $2$ and normal, and the quotient $\mathbb{Z}_4/H$ is of order $2$, hence cyclic of order $2$. If it were a semidirect product of $\mathbb{Z}_2$ by $\mathbb{Z}_2$, then being abelian it would necessarily be a direct product, and so would have exponent $2$; so it cannot be written as a semidirect product.

As I mentioned, every group can be expressed as a sequence of extensions using simple groups. By the Jordan-Hölder Theorem, although the sequence is not unique, the precise simple groups that occur is (counting multiplicity).

The definitions look quite similar: we just drop the condition of normality for one factor when going from direct product to semidirect product; we just exchange "there is a subgroup isomorphic to $N$ that maps isomorphically onto the quotient" with "the quotient is isomorphic to $N$" in going from semidirect product to extension. But the consequences of these "little changes" is large. Much like the difference between "finite abelian group" and "finite group" looks very small (just a single line dropped), but the implications in our ability to classify/understand the objects in question are enormous.