Mixing and mastering are two separate processes that go towards having a finished song or record. Mixing is basically refining the combination of tracks or instruments. At its most basic it would involve deciding which elements you wanted to be louder than others. Other things that are adjusted in mixing are "panning" (where different instruments sit in the stereo field), changing the EQ on individual instruments and adding effects to them.
Once a track is mixed mastering is done to the final audio file of the mix. Whereas in mixing processing was applied to individual elements (eg. the kick drum or the vocal), in mastering processing is applied to the finished mix as a whole. This allows the mastering engineer to bring the mix more into line with other similar mixes, typically commercially released ones, by bringing it up to a similar overall level and making any final adjustments with EQ, compression or other subtle aspects of processing. Its important to bear in mind though that mastering can never rectify fundamental problems with the mix but merely uses a fairly broad sweep of the brush to the overall sound. One of the reasons mastering is also considered so important is that it allows a further person with a fresh set of ears to give the mix a final once over and hopefully add their perspective. Another thing a mastering engineer would do would be balance different songs that appear on the same body of work (eg. an album) so that they work well as a whole.
Tom McFall is an engineer, producer, and songwriter who is working with globally successful artists like REM, Snow Patrol, Bloc Party and Biffy Clyro. He is also a music production tutor at British & Irish Modern Music Institute. Discover Tom’s work on his website: https://www.tommcfall.com/