how does voip and asterisk work together?
That’s a very vague question. Perhaps you should read up on asterisk a bit.
There is a great book out there called “Asterisk: The Future of Telephony”.
You can download it and read up. All your questions will be answered.