A sex crime is a criminal offence classified as such in a particular legal jurisdiction.
The common understanding is that these are acts where the motives are primarily sexual gratification, with an implication of non-consent on the part of one party. However, entirely consensual and conventional sex acts between partners are classed as sex crimes in some places. So, for instance, age difference between the partners may automatically put an act in this class. In the US, several states classify conventional intercourse between a girl and boy as non-criminal if both are, say, under 18 and older than 14, but as a sex crime if one partner is older than 18.
Acts that may be classed as sex crimes include rape and molestation, but may also include acts of voyeurism or display involving invasion of privacy or exposure to public view. In most places in the developed world, mere possession of images of underage persons in salacious poses or positions is a sex crime, regardless of whether sex acts or nudity is actually involved.
In a BDSM context, depending on jurisdiction, such acts as bondage, non-conventional sex (eg, anal sex, oral sex, unusual positions, ...), though desired by both parties, may be treated as a sex crime by police, prosecutors or courts. Actually flogging, tawsing, paddling, etc. may be treated as a sex crime or as assault and battery, depending on the jurisdiction, and regardless of consent of both parties.