It is usually provided to the user by the administrator.
Someone has to order a block of DID numbers, create inbound rules using those numbers, and assign the outbound caller ID to the extensions. If all of that has been done, then I assume that when calling an outside number, the DID would appear in the called parties set. The DID should also be consistent with all of the other phones in the office (assigned a DID), where the last few digits of the full DID number are made up of the extension number.