How to implement a xor gate with nand gates
You've got a good start. Just re-distribute the second term over the first:

(A + B)(AB)' = A(AB)' + B(AB)'

And then apply De Morgan to the whole thing:

A(AB)' + B(AB)' = ((A(AB)')'(B(AB)')')'

The Boolean expression gets to be a little hard to read, but it translates to the following circuit:







simulate this circuit &ndash; Schematic created using CircuitLab

Note that the exact same network works if all of the NAND gates are changed to NOR gates, except that you get an XNOR gate &mdash; the output is high if the inputs are equal.