Each carrier buys “blocks” of numbers for use.
So for example in Australia you can download this file. And see which telco has “bought” which numbers.
https://thenumberingsystem.com.au/#/number-register/search
Apple’s iMessage is another topic. And it checks an internal apple data base to see if the number is registered before sending an SMS.
Latest Answers