Mastering has many tasks, but in general you could say that it's the stage where you prepare the track for the real world (compared to mixing, which is more about shaping and balancing the different sounds in the track).
If I remember it right, these are the common steps (might be wrong though, but this is pretty much in general):
First step is when you do fine adjustments to the whole track, like very subtle EQ, compression, M/S, or saturation moves on the whole track just to see if you can give it a lift and balance it as a whole, as well as making it sound good on various types of soundsystems (meaning you reference the track on a lot of systems and use a lot of reference tracks and adjust different things).
Next step is often a loudness increase to make it more competitive on the music market.
Though if you're against the loudness wars and such, then there's no need to care about this step.
Next step would be exporting the track properly - normalizing the amplitude to where you want it (often -0.3 or -0.1 dBFS), then applying dither if you're going with 16-bit for bitdepth, etc.
Next step is when you're dealing with more than 1 track, as if you're producing an EP or album. Then you balance the levels between the songs, and set the suitable length of silence between the songs.
Then you need to set the metadata; author, album name, song title, and so on.
Then you have some other things to do if it's through a label.