How can you show there are only 2 nonabelian groups of order 8? It's often said that there are only two nonabelian groups of order 8 up to isomorphism, one is the quaternion group, the other given by the relations $a^4=1$, $b^2=1$ and $bab^{-1}=a^3$. 
I've never understood why these are the only two. Is there a reference or proof walkthrough on how to show any nonabelian group of order 8 is isomorphic to one of these? 
 A: A very down-to-Earth approach might be:
Let $G$ be a group of order 8.
Exercise 1: Show that the maximal order $m$ of an element $x$ of $G$ is either 2, 4, or 8.
Exercise 2: Show that if $m=2$, then the group $G$ is abelian.
Exercise 3: Show that if $m=8$, then the group $G$ is abelian.
Ok, so that leaves us with the case $m=4$. Let $x$ be an element of order 4. Let $H\simeq C_4$ be the subgroup generated by $x$.
Exercise 4: Show that $H$ is a normal subgroup of $G$.
Let $y\in G, y\notin H$ be a fixed element.
Exercise 5: Show that $y^2\in H$.
Exercise 6: Show that $yxy^{-1}$ is an element of order 4 in $H$.
Exercise 7: Show that either $yxy^{-1}=x$ or $yxy^{-1}=x^3$.
Exercise 8: Show that if $yxy^{-1}=x$, then $G$ is abelian.
Ok, so we must have $yxy^{-1}=x^3.$ Assume that this is the case in what follows.
Exercise 9: Show that if $y$ is of order 2, then $G$ is isomorphic to a dihedral group.
Exercise 10: Show that if $y$ is of order 4, then $y^2=x^2$.
Exercise 11: Show that if $y$ is of order 4, then $G$ is isomorphic to the quaternion group (or more precisely: the group of units of the Lipschitz' order)
Rejoice!
Remark: You won't need the result of Exercise 5 until the two last ones. I just added it there, because the element $y$ was introduced at that point.
A: Here's the proof that there are exactly five nonisomorphic groups of order $p^3$ for every prime $p$, as it appears in Marshall Hall's Theory of Groups.


*

*The abelian case is easy: you have $C_{p^3}$, $C_{p^2}\times C_p$, and $C_{p}\times C_p\times C_p$.

*The nonabelian case. There can be no element of order $p^3$, because then the group is cyclic. 


*

*If all elements are of order $p$, then $p$ must be odd (otherwise the group is abelian). The center of $G$ is of order $p$ (since the quotient must be of order $p^2$ and isomorphic to $C_p\times C_p$); let $x$ and $y$ be elements of $G$ whose images generate the two cyclic factors of $G/Z(G)$. Then $x^p = y^p = 1$, and $x^{-1}y^{-1}xy\neq 1$ (otherwise, $G$ would be abelian), but must be central; so $z=x^{-1}y^{-1}xy$ generates $Z(G)$. So $G$ is given by
$$G = \langle x,y,z\mid x^p=y^p=z^p=1, xy=yxz,\ xz=zx,\ yz=zy\rangle.$$

*If there is an element $x$ of order $p^2$, then $\langle x\rangle$ is a maximal abelian subgroup of $G$, and normal (since its index is the smallest prime that divides $|G|$. Let $b\notin A$. Then $b^p\in A$, and $b^{-1}ab=a^r$ for some $r$; since $G$ is nonabelian, $r\neq 1$. Since $b^p$ commutes with $a$, $a^{r^p}=a$, so $r^p\equiv 1\pmod{p^2}$. From Fermat's Little Theorem, $r^p\equiv r\pmod{p}$, so $r\equiv 1\pmod{p}$. 
Write $r=1+sp$, and let $j$ such that $js\equiv 1\pmod{p}$. Then
$$b^{-j}ab^j = a^{r^j} = a^{(1+sp)^j} = a^{1+spj} =a^{1+p}.$$
Since $(j,p)=1$, $b^j\notin A$, so replacing $b$ with $b^j$, we may assume that $b^{-1}ab=a^{1+p}$.
Now, $b^p = a^t$, and $t$ must be a multiple of $t$, because $b$ is not of order $p^3$. Write $t=up$, so $b^p=a^{up}$. Then we have:
$$\begin{align*}
(ba^{-u})^p &= b^pa^{-u(1+(1+p)+(1+p)^2 + \cdots + (1+p)^{p-1})}\\
&= b^p a^{-up-up(1+2+\cdots  + p-1)}\\
&= b^p a^{-up-up\binom{p}{2}}.
\end{align*}$$


*

*If $p$ is odd, then $up\binom{p}{2}$ is a multiple of $p^2$, so we get $(ba^{-u})^p = b^pa^{-up} = b^pb^{-p} = 1$. Setting $c=ba^{-u}$ we get $c^{-1}ac = b^{-1}ab$, so the group is presented by
$$\langle a,c\mid a^{p^2} = c^p = 1,\ ac = ca^{1+p}.\rangle$$

*If $p$ is $2$, however, we get $(ba^{-u})^2 = b^2a^{-up-up} = b^2$. We have two possibilities: it could be that $b^2=1$, in which case we get the same presentation as above:
$$\langle a,b\mid a^{4} = b^2 = 1,\ ab=ba^3\rangle.$$
Or it could be that $b^2=a^2$; we must have $b^{-1}ab=a^3$ (it cannot equal $a$, because then $a$ and $b$ commute and $G$ is abelian), so the group is given by
$$\langle a,b\mid a^4=1,\ a^2=b^2,\ ab=ba^3.$$
Burnside uses essentially the same approach, though he only deals explicitly with odd $p$; the classification for groups of order $p^3$ takes up about two pages (one paragraph, but he invokes results covering two previous pages). He then proceeds to those of order $p^4$; that takes four and a half pages (plus invoking stuff that covers at least one previous page). He only lists those of order $2^3$ and $2^4$. 
A: Let $G$ be non-abelian group of order 8.
By Sylow theorem, $G$ will have subgroups of order 2.


*

*If $G$ has unique subgroup of order 2, then $G$ is quaternion (Ref. Theorem 12.5.2, Theory of groups- Marshall Hall). ($G$ can be cyclic also, but we have assumed it is non-abelian.)

*If $G$ has more than one subgroups of order 2, then they will be $1+2k$ in number for some $k\geq 1$; so it is atleast $3$; let $H_1, H_2, H_3$ be three distinct subgroups of order $2$.
If $H_1\triangleleft G$, then $G/H_1$ is abelian (since its order is 4), we conclude that $[G,G]\leq H_1$, hence $H_1=[G,G]$ since $G$ is non-abelian.
Then  observe that $H_2$ can-not be normal in $G$, otherwise $H_2=[G,G]=H_1$, contradiction.
(So we have found a subgroup of order $2$ which is not normal in $G$.)
$H_2$ is a subgroup of $G$ index 4, there is a homomorphism $\phi \colon G\rightarrow S_4$, with $ker(\phi)\subseteq H_2$ (See "Generalised Cayley's theorem" - Introduction to Theory of Groups, Rotman).
But $ker(\phi)\neq H_2$ since $H_2$ is not normal, so $ker(\phi)=\{1\}$; so $G$ is isomorphic to a subgroup of $S_4$ of order $8$; it is a Sylow-2 subgroup of $S_4$; and it is $D_8$ since when considering a square with vertices labelled $"1,2,3,4"$, its symmetries in terms of permutations give $D_8\leq S_4$.
Conclusion:

$G$ is either quaternion or isomorphic to Sylow-2 subgroup of $S_4$ which is dihedral group of order 8.

A: You probably meant $bab = a^3$ in the above.
The following steps should also work. In order not to spoil the fun for you,
I omit all the details.
Let $G$ be a nonabelian group of order $8$ and let $Z$ be its centre.
(1) From the class equation we know that $|Z|$ is divisible by $2$,
and hence $|Z|\gt1$
(2) If $G/Z$ were cyclic then $G$ would be abelian. Therefore only the
case $|Z|=2$ is possible and we know that $G/Z$ must be isomorphic to 
the Klein group.
Now let $Z=\{1,z\}$ and take $a,b,c\in G$ with $G/Z = \{Z, aZ, bZ, cZ\}$.
All squares a^2, b^2, c^2 lie in $Z$ and we may take $c=ab$.
Now the rest is a case by case analysis
(3) We cannot have $a^2 = b^2 = (ab)^2 = 1$, because then every element
of $G$ would have order $2$, forcing $G$ to be abelian. So at least one of
those squares must equal $z$. In particular $G$ has an element of order $4$.
(4) If two of the above squares equal $z$, then so does the third. For
instance, suppose $a^2 = z = b^2$. Then $(ab)^2 = 1$ would give
$ab=zbaz=ba$ and $G$ would be abelian.
So now we arrived at two possibilities (up to permutation of $a$, $b$ and $c$):
case (i):  $a^2 = b^2 = c^2 = z$.
Then $G$ is the quaternion group.
case (ii)  $a^2 = z$, $b^2 = 1$.
Then $bab$ lies in $aZ$. Because of (4), $bab=a$ is impossible and therefore
$bab = az = a^3$.
A: See www.math.uconn.edu/~kconrad/blurbs/grouptheory/groupsp3.pdf, which discusses groups of order p^3 for any prime p and treats the case p = 2 first.
