This is the final stage of the recording process. When you go to a studio to “record” this is not part of what you’re paying for unless you negotiate that. It’s a needed and necessary final process more often than not done by someone different than the recording engineer.
So what is it? It’s both a creative and technical process that adds that final finish to a song. A great mastering engineer will help bring out nuances that will translate well into many different listening environments (ear buds as well as home-theatre systems). In the case of an EP or LP they’ll make sure all the songs have the same sonic sound that help them to feel as if they’re all part of the same production. It’s also where the song(s) are converted to the standard format for playback on CDs.