Let’s use a simple example:
Company A has 1,000,000 shares outstanding with a value of $10 each, and a total corporate market value of $10,000,000.
It decides to spin off Company B. They will use an M&A consulting firm and an Investment Bank to do some analysis on the value, carve up the debt obligations, etc. But, in the end soemthing pretty simple happens. They need to decide how many shares to issue of the new stock. Let’s say in this instance they decide the Company that they’re going to spin-off is worth 2,000,000. They might choose to issue 200,000 shares or 100,000 or really any other number that is reasonable (you don't want it to be a penny stock or to have some really high /share because that can be a barrier to entry for some investors, plus it just looks funny).
So, let’s assume they decide to issue 400,000 shares.
Say you owned 100 shares of Company A. You would keep all 100 shares of Company A, and you would recieve 40 shares of the new Company B (you get a pro-rata amount).
If the company was correct about the valuation, you would expect that Company A is now worth $8,000,000, and with the same amount of shares outstanding, each share is now worth $8.
At a value of $2,000,000 and with 400,000 shares issued in Company B, each share would be worth $5.
So, your 100 shares of Company A would be worth $800 (1008) and your 40 shares of Company B are worth $200 (405). So, in this perfect scenario you end up with exactly the same amount of value as you had before.
Of course, it never works out this way in real life. The combined value is usually less or more than the starting value, which determines if it was a good idea or not (at least in the very short run in the eyes of the investment community).
There are lots of nuances that change things, but that’s the basic idea of it.