How does the ladder work?

Let’s say when I challenged someone he was ranked 10th and I was ranked 20th. But by the time I won him both his rank and and my rank has already changed drastically. How then would my ranking change? Would it be based on the new rank or the old rank?

It’s based on the new rank. So if you start off at 10 and 20, but by the end of the game they are 5 and you are still 20, but you manage to win, your new rank will be 5, theirs will be 6. Conversely, if by the end of the game you are 5 and they are still 10 and you win, then there will be no change to the rankings since you are already ahead.