A simple answer to your question is that you're partially right and partially wrong, because you're using two distinct concepts interchangeably.
Biological sex is genetically determined, and there are essentially two possibilities: male and female. Furthermore, there are rarer chromosomal combinations (like XXY, for example) and certain gestation and developmental conditions which may lead to ambiguous or unusual expressions of primary and secondary sexual features (like hermaphrodites, for example). But for the sake of the distinction which is meant here, let's just accept that there are two biological sexes.
Gender is a psychological, social and cultural construct which has more to do with societal roles, expectations and boundaries, as well as with the psychology of personal identity and its expression. Someone who is born with a certain reproductive system may, psychologically and socially, identify more or less with the set of roles and expressions which society ascribes to the traditional gender associated with that reproductive system. So, someone may be a functioning biological male and still develop an identity which is much closer to that of the female gender, or with an altogether new set of characteristics which forms a new gender category.
A very interesting example of gender variety is provided by the Bugis, a major ethnic group in Sulawesi, Indonesia. I leave you the link to the wikipedia article on it, if you'd like to check it out.