Your gender is not your sexual orientation. It's not how you have sex, or whether you do or not. It's more than your sex organs, more than your genotype. Humans being the complex beings that they are, they get a whole host of secondary sex characteristics and a sharp eye for detecting them. The hormones that shape our bodies in the womb affect us all of our lives: they change the way we think, the way we act.
Socially, we place a huge imperative on sexual relations. That's natural, considering that the way our species keeps propagating is by sexual reproduction. Life itself is strong willed.
Gender is maleness or femaleness — a scale, though most people fall neatly toward one end or the other, though not usually all the way. There's certainly men out there who really set off our brain's maleness detector, and women who do the same thing (or were you looking at the woman in the red dress?). Gender's not that complex.
The part that's really interesting is how we see ourselves. Some people don't feel comfortable placing anywhere on the scale, or many places depending on what they feel like. They've learned to fool everyone, or just do it naturally. It's gender identity that varies so much. Some people look in the mirror and imagine sculpted muscles so strongly they believe they have them. Their identity is strongly masculine, they go about their lives acting as if that were their nature. Another person might be more objective and decide they want to be that way, and spend the time to build muscles and play the part. (All the world's a stage.)
Some people have a gender identity that's so cross-wired that they have a hard time putting the mismatch aside. For some people, it's a mild discomfort, something that is an occasional bother. For others, it is psychologically crippling or they act so inappropriately according to those around them that people make their lives hell. Some people have never felt comfortable with any role they've seen played out. Humans are social creatures, and we learn fast. We spend our first ten or so years picking up the subtlest details of human interaction, and forming our personal identity happens all throughout those years and on into teen hood.
That's what gender and gender identity are.