It would help to know what kind of barking your dog is doing. In that moment, is he excited? Is he aggressive? Is he worried?
I’m going to assume he doesn’t want them to leave or, more likely, he wants to go outside with them.
Right before people leave, grab a big handful of treats. Have your dog sit near you and as people go to the door, start saying “good dog” and giving him treats. As they are leaving, as long as he doesn’t bark, continue to reward him. If he barks, tell him “no bark” and then ignore him. If he stops even for a second, say good dog and give him a treat. Gradually, over many iterations, make the pause longer before you reward it. Make sure he continues to sit next to you. You may have to practice this dozens of times.
The key is to catch him *before* he starts barking. You want to reward good behavior (not barking when people leave) and if you wait until he’s barking it’s too late. Do not give him a treat for barking!
In addition, I would give him a specific place to sit as people are leaving. (I do this with my dog for when people are arriving, as that’s his challenge.) Then when people leave you can say “go to your bed” or whatever you want to call it.