Never thought of it like that. Gender is what makes you male or female and sex is what people do.
My informant went further than that, saying that gender has no direct relationship to one's physical equipment. He went into greater detail, re hormone production during, um, pre-adulthood, and other arcane stuff, but lost me along the way. It is pretty clear to me that transgenderness is biologically and psychologically more complicated than my tired old brain will grasp. It is what it is, is what.