How do I record the gameplay audio if I'm using headphones?

So I want to record the sound I hear on the headset, for example my friends talking on teamspeak as well as my voice. How do i get it to record my friends voices if I don’t have speakers and I’m listening through headset and also record what I’m saying into the microphone?

You have not said your version of Audacity or Windows (see the pink panel at the top of the page).

Doesn’t Teamspeak 3 or higher have a built-in recording tool to record you and the other participants:

Audacity can only record from one source at a time. So the only method using Audacity without special tools is to send your mic to the output and record stereo mix, assuming it is a headset with pink and green connectors. There are many disadvantages in doing that and it may not work at all. Use a tool meant for the job.