There is a so-called gap limit. In Electrum, it's 20 by default but can be changed. But if you changed it up, remember that! Preferably write it next to your wallet's seed.
This means that the HD wallet determines the first 20 addresses and checks on a server whether any of them have every been involved in a transaction. Let's say these addresses are numbered. Number 7 is the one with the highest number to ever have been involved in a transaction. Then, 7+20 = 27 is computed and all addresses up until and including 27 are checked. It's found that 21, 23, and 25 have been involved in transactions. Then, 25+20 = 45 is computed and all addresses up until and including 45 are checked. It's found that none of the addresses from 28 to 45 ever had activity on them. Therefore, the search is stopped because there is a cap of at least 20 addresses. If address 46 had a transaction on it, that's not discovered until the user uses the wallet enough such that that address is searched for activity or the gap limit is increased.