If Player-A shoves for $123, and Player-B shoves for $300, and everyone else folds, then Player-A is can only win $123 of Player-B's stack, so the remaining $177 goes back to Player-B.
To make it morecomplex...
Lets say Maid Marian goes all-in for $1,000. All her chips go into the pot.
MrSticker has good cards and wants to isolate, going all-in for his $2,000. All his chips go into the pot.
I look down and see Kings, so I go all-in for my $3,000. All my chips go into the pot.
Dakota-xx with $4,000 dislikes her hand in the small blind and folds.
Enty with $5,000 (rigged!) dislikes his hand in the big blind and folds.
If Maid Marian wins, she can only get $1,000 from MrSticker and $1,000 from me, plus she takes the blinds and any antes as that's all part of the main pot she was a part of.
So if she won, there would appear to be $3,000 left in a side pot between MrSticker and I. (Because MrSticker put in $1,000 more than she could take, and I put in $2,000 more than she could take) But MrSticker is only entitled to $1,000 of what I went all-in with, because he only put in $1,000 into that side pot.
So if MrSticker wins that hand he gets $2,000 and the remaining $1,000 gets returned to me. (I still lost $2,000 that hand, $1k to each player)
The reason my entire stack was pushed into the pot even though I had $1,000 more than MrSticker is because Dakota-xx and Enty had me covered so they get to see how much they can potentially win. When I go all-in I can potentially lose my entire $3k. But as soon as they both folded, I knew that no matter what happened I'd be getting $1,000 back.