Your telephone is connected to an exchange via trunk lines. The exchange has all the switching equipment to do the connection. It also supplies all the signaling such as tone frequencies.
It used to be, the switching was electro-mechanical such as strowger being activated by pulses coming from the rotary telephone set. But nowadays everything is digital.
The exchange is the one giving you dial tones, busy tones, etc. and also connects to another exchange based on the three-digit numbers after the area code.
This is just a brief summary of the telephone system. If you need to know more, go and buy a book about telephony.