Actually, I'm not sure they DO know, at least not in the way you mean.
It seems clear they keep some sort of running total, since they know when you top out. But passcodes can allow you to exceed this limit (clearly) which is where the wierdness starts.
Paging through the items tabs, you can get the number of each item that you have as well, and you can interact with them in any ways available from these screens (drop anything, or fire an XMP, basically). Dropped items can't be retrieved, however, since you're already full.
However, while over 2000 items, some things seem to periodically go missing. I currently have about 2500 total items... but periodically some (mostly resonators) go missing in contexts outside the item list.
Resonators can't be deployed, etc., because the app believes I don't have them... even though I can pull up the OPS screen and drop them.
My theory is that the 2000 item limit, while not enforced when passcodes are applied, is hardcoded into some other locations, such that if you do have 2000+ items, the game will still stop looping through your inventory after the 2000th item whenever it's checking to see if you have something that you can use in a given context. The only way I've found to nudge this lose is to exit. force stop, clear cache, and wait a bit, then try deploying again without going into OPS. This will bring a few new "missing" items in range. This has been pretty consistent (though I suspect that "wait a bit" may be the only really efficacious part).
The inventory screens presumably use different sorting methods, most likly sorting on item type before counting up total available, making the 2000 limit irrelevent. I'm not an expert, but depending on how the data is stored I can think of a couple of ways they might
be handling things that could result in this setup.