but to me, mixing is putting together all the elements of a track together, getting the right levels, eqing, compressing etc to make it sound as good as possible.

Mastering is the very final stage where they bring it to commercial levels, make sure all tracks of an album are at equal volume and if they need to - apply some minor eq and compression.

People sometimes seem to think that you can make a song sound good by sending it to an engineer for mastering, then complaining when it comes back as bad as they sent it. If a song sounds bad after mixing it will sound just as bad at mastering, so in that sense, no mastering isn't essential unless you're releasing something commercially (imo)

If whoever's mixing it does their job really well, mastering is a pretty brief process; on the other hand, producers who are used to doing both may well cut corners at mixing, knowing they'll settle it at mastering. Or might dip back into mixing to aid the mastering process. It's all potentially quite fluid.

The most basic difference in my (amateur) mind is that mixing/producing is concerned with the sound/EQ/etc. of each individual 'thing' that's been recorded, and then how those sounds sit together in the aural spectrum - whereas mastering is concerned with the mix taken as a whole, and determines the final colour of the track overall.

It's pretty challenging to master against the grain (so to speak), in the sense that if it was mixed like a heavy metal song, mastering it like a pop song is not really going to make it sound pop. But extremes like that aside, it can certainly be the determining factor in the final vibe of the song, and have no doubt a bad mastering job can totally sabotage good mixing.