I need to understand the correct Bitcoin address workflow for transactions. I created an address a while back with a common wallet and sent some coin there. The address is at segwit m/49'/0'/0'/0/0. I then spent some coin from that. When I looked up the address on the blockchain, I noticed that the balance was 0. The transaction that occurred had two output addresses. The funds were sent to two addresses. The second is the non-segwit address of the person of who I sent the funds to. The first was segwit m/49'/0'/0'/1/0 (address from my wallet). It appears that the wallet moved my funds to a new address in my wallet. I.e. m/49'/0'/0'/0/0 -> m/49'/0'/0'/1/0.
Should a wallet always move the left over from m/49'/0'/0'/0/x to m/49'/0'/0'/x/0? Is this logic standard practice? Or is this specific to the wallet I used? Is there a recommended practice? I need to know because I am developing a wallet, and I need to follow standard practice.
What should happen when I transfer the funds from m/49'/0'/0'/x/0 to another address, and there are leftovers? Where should the new address for the leftovers be moved to? m/49'/0'/x'/0/0?