For most purposes, the terms sex and gender are interchangeable. There are not many people who will be confused when met with a box on an immigrations or medical form asking "sex" (although I have seen this answered with a yes/no/rarely (etc.) These people really are confused by the question.) More and more often, this is replaced by a choice: M/F.
For purposes of clarity, the World Health Organization defines sex as referring to either of the two main categories of biological and physiological characteristics that define men and women, as well as most living things. The answer to sex? is male or female (or unknown). Males have male sexual organs, make more testosterone than females, are often larger overall, may be more colorful, etc. Females have ovaries, produce more estrogen, gestate young or lay eggs, may be samller generally, more subdued in coloration, etc.
The WHO lists gender as that which refers to the socially constructed roles, behaviours, activities, and attributes that a given society considers appropriate for men and women. The answer to gender? is masculine, feminine, (or, in the case of language and microorganisms, neuter). Examples of gender differences are, e.g. in the US, women earn significantly less money than men for similar work; in Saudi Arabia men are allowed to drive cars while women are not; in most of the world, women do more housework than men; in some countries, women alone are allowed to own land; in others, women themselves are property.
Since the recognition of gay rights, sex and gender have become politicized terms. Still, we have documents proclaiming that "X" does not discriminate on the basis of age, race, creed, color, sex (more often than gender), national origin, marital status, age, sexual orientation, military status, genetic predisposition or carrier status, disability, or any other, etc.
A good indicator of the difference between sex and gender is that in language, non-living things have gender. In French, house is feminine (la maison), fire (le feu) is masculine. In Latin, table (mensa) is feminine, field (ager) is masculine, and entrance (limen) is neuter. None of these have a sex. In some Latin words, sex and gender are contradictory: a female poet is still a poeta (masculine), a female farmer is masculine (agricola) and an idiot (idiota) is always masculine.
Therefore male and female are sexual categories, and masculine, feminine and neuter are gender categories.