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.