How do I know when to stop breastfeeding my baby?

I usually wait till he pulls away and sometimes when we reach 20min I’ll pull away but he’ll cry

He mostly ends up spitting up,

Tips?