  We study the subgroup structure of the infinite torsion $p$-groups defined by
Gupta and Sidki in 1983. In particular, following results of Grigorchuk and
Wilson for the first Grigorchuk group, we show that all infinite finitely
generated subgroups of the Gupta--Sidki 3-group $G$ are abstractly
commensurable with $G$ or $G\times G$. As a consequence, we show that $G$ is
subgroup separable and from this it follows that its membership problem is
soluble. Along the way, we obtain a characterization of finite subgroups of $G$
and establish an analogue for the Grigorchuk group.
