This is a very big topic that can not be answered in a simple Q and A format on this site.
If you just want to write programs to talk over the internet, I would recommend learning the basics of programming. As you learn programming you will start to understand how things talk to each other and the whole "client server architecture" and programming with sockets.
If you want to learn the nuts and bolts of "How the internet works" and don't really care about the programming side, I recommend listening to the Security Now! episodes on "How the internet works". I will link the episodes directly talking about the topic but I do recommend going and listening to the other episodes in between the ones I listed (especially the Q&A episodes following each linked ep.)