A record company pays for everything that needs to be done to make a CD.
There needs to be money for things like:
Record companies often give their artists an advance, too - money for the artist to live on while making the CD.
- recording - studio and engineer time
- mixing - to make sure all the sounds can be heard
- mastering - sorting out the final copy
- pressing - actually making the CDs
Getting the money back
Any profits that the CD makes helps to pay back this money.
If it is a flop, it is very unlikely that the artist will be expected to return the money.