A common response to "Is there a difference?" or "What is the difference?" is that what we consider the sex of an individual often has to do with what parts of anatomy they might have, chromosomal makeup, and hormones. So, in this way, "sex" refers to biology. Gender and gender identity, in particular, has to do with how that person thinks and feels about themselves and how they wish to be seen in this world.
Unfortunately, "gender" gets used to mean not only an individual's concept of themselves, but also the cultural norms expected of someone with a particular anatomy. For example: if you are born with a certain set of features, you get classed as a "girl" and you're expected that your role is marriage and children. Education may be limited to you, or you may be expected to like certain hobbies over others, etc.
So in this way, someone can be cisgender - as in, their concept of themselves fits with what society expects someone of a particular set of biology to be - but also gender non-conforming in some behaviors. For example, a teenage guy can be perfectly happy being referred to as a guy, but wears his hair long, wears black nail polish, and hangs out talking about poetry - some of these behaviors might be considered gender non-conforming because, in the US, there can be a lot of push back about a guy reciting poetry. Poetry is seen as feminine, and a guy liking poetry is often seen as as being too girly.
If someone does not necessarily identify as the gender expected of them, they are at a much larger risk of being abused and bullied. The Trevor Project and Trans* Lifeline have resources on this. When I say "bully," I don't mean the occasional side-eye or "How can you let your child live like that?" There is direct correlation to transgender, intersex, and gender non-conforming individuals being physically abused, receiving death threats, thrown out of their parents' or guardians' houses, being sexually assaulted, and more.
Because of this, there is an effort for increased awareness and inclusion. Terms to describe a person who does not identify with the gender expected of them at birth include gender non-conforming, transgender, trans* (the asterisk can act as an inclusivity marker), nonbinary, genderfluid, and more. Different cultures also may have their own terms, as multiple genders being acknowledged amongst different cultures has been a thing throughout history. Checking out Genderqueer Identities is a good start to get a handle on these terms.
So you might think "biological sex" is an easier definition! After all, science, right?
However, even this explanation breaks down. Biological sex - what is intended with M and F markers on official documents such as medical records - isn't just about if someone has a vagina or a penis. (The "sex" markers are often used as shorthand, and the rhetoric often goes into "but biology," but nature is more complicated and varied for humans to stick it into neat boxes very well.) For example, a woman might have had her uterus removed for some reason - and thus cannot bear children. If "being a woman" is equated to reproductive capacity, then that definition breaks down, doesn't it? Plus, aside from presence of particular organs, hormonal makeup comes into play, too. There are men with high estrogen and women with high testosterone. This Nature article details how even the "biological sex" rhetoric can be blurry, and how it might intersect with legal definitions and binaries.
It seems a lot to understand all at once, and may be challenging. The point is: