Gender is a social construct of societal differences between males and females. Gender is not always associated with sex - the biological differentiation between males and females based on sex organs, sex chromosomes, or both - but is in many cases.
According to Sociologist Zuleyka Zevallos, gender construction depends on "how societies determine and manage sex categories; the cultural meanings attached to men and women’s roles; and how individuals understand their identities."
Different societies have different sex categories. For instance, most Western societies classify individuals as either male or female. In these societies, if you are born with the reproductive organs of one sex but have the chromosomal pairing of another, the individual is usually assigned a sex based on their chromosomal pairing and then undergo reconstructive surgery so their anatomy reflects this sex. Other times, doctors can make the call about what sex the child is based on what they feel is the more prominent genitalia. This can lead to great social and personal quandaries when the child hits puberty and their body begins to react in a way sexually that they may not have been raised. Today, there are many movements to allow the child to identify one way or the other, wait until puberty, or assign sex based purely on chromosomal pairings (as this will affect puberty later in life).
Cultural meanings attach to men and women's roles vary greatly from culture to culture and even within cultures. For instance, the "stereotypical" vision of men as tough, out-of-the-house hunters and women as motherly gatherers is not so stereotypical or wide-spread as one might assume. For instance, in the US society and culture, we have metrosexuals, househusbands, androgyny, cross dressers, etc that occupy "atypical" gender roles in US society. In other societies, two-spirits, hijras, khanith, "girly boys," and more represent the fluidity of gender roles.
Lastly, how an individual identifies plays a great deal into gender construction. Cis-gendered people are those whose anatomical structure matches with the gender they've been classified and which they identify as. Trans-gendered people are those whose anatomical structure doesn't match the gender they've been classified or what they identify as. Intersex people are those have ambiguity between their sexual organs, chromosomes, hormones, etc as detailed in the third paragraph above. Gender Queer are those who either don't identify as any gender or draw on different aspects of different genders. Third gender are those who do not accept the binary man/woman construction of gender found in most societies.
One must remember that because it is a social construct, gender is fluid and changes from culture to culture, place to place, and person to person. There is not one definition of gender.