There are many elements that go into understanding gender. Gender is one's perception of who they are internally and who they express themselves externally to the world. Ultimately it is their choice to decide what they want to identify as.
A lot of people mistakenly correlate gender and sex as the same thing. They are not. Sex is the biological genitalia on a person. (For example, someone may be born with male anatomy, but as they grow older may feel that they truly identify as woman.) Some people may just identify with the anatomy they're born with as well, so therefore that is their gender identity. There is also gender expression. Gender expression is how a person may want to be viewed externally towards the world. This may not determine their gender, but this is what they feel comfortable in showing. There is also gender attraction. This doesn't necessarily determine your gender, but it's just who you are attracted to, whether you're heterosexual, bi sexual, pan sexual, a sexual, or homosexual. However, male and female are not the only gender identities. Some people do not feel that they fall into the male or female category, so they fall into the gender-queer spectrum. For example some may use the pronouns, they, them, xi, xer, ey, etc.
Some people also may identify as grey gender, or a gender since they feel they do not fall into the male or female gender category. In addition, someone may also identify as intersex. Intersex is is a general term used for a variety of conditions in which a person is born with a reproductive or sexual anatomy that doesn't seem to fit the typical definitions of female or male. People who are intersex have male and female chromosomes. That's all it is. Someone who is intersex may also not want to identify that way. Going back to gender identity, they maybe feel they're not what they've been biologically assigned at birth.
Why am I telling you this? It's so unbelievably important to understand the elements of gender, in order to understand people! There is always so many misconceptions and intolerance towards people who may be different than you, but maybe with a bit of explaining and educating, a huge difference can be made. It's important when understanding gender that you really do your best focusing on learning people's pronouns. Pronouns are literally how a person defines themselves every single day, so it is important to make the conscious effort to get them right. It's also a major sign of respect when you do get them correct as well.
Gender can be a very confusing thing, but with a little patience, it is possible to really understand it. We're living in a time where it is important to expose older people, but also younger generations of what gender really is and what all of these definitions mean. It's important to educate people now so there are no misconceptions and people can truly understand each other.