Could someone (who is in the writing/publishing industry) or knows something about it, please explain how royalties work with publishing companies and writers/authors.

I know it may vary, but generally, for a new comer, and for a novel and or collection of short stories. I hear generally it's 50% of all profits. But can someone shine some more detail to it? Like how the pay works, and under wut circumstances you get it, and how a bit of the math works, etc...

Thanks,
T.