I worked for one employer with an algorithm for this (yes, it was a software company, why do you ask?).
Certain people are designated "keyholders". This is because the last one out didn't just set the alarm, they also locked up, for which they each had their own set of keys. You could use a different name if there are no keys. The algorithm works if everyone is a keyholder, however at a minimum you can't be a keyholder if you haven't been shown how to work the alarm and this algorithm.
At the start of the day, at least one keyholder and preferably more becomes "tagged". This could be decided in daily standup, or could be the same person/people every day, provided that when that person isn't in, someone else becomes tagged in their place. It might as well be people who are likely to leave late, to save a lot of unnecessary checking right at close-of-play, so if you have people who typically work 10-6 instead of 9-5 then they are good candidates to start out tagged every day.
A tagged keyholder is not permitted to leave the building for the day without first doing one of two things:
- Find another keyholder, say to them "tag", and receive acknowledgement of the tag. This other keyholder thereby becomes tagged. Probably common-sense, but since I called this an algorithm I'll state it explicitly: having tagged another keyholder, a keyholder may decline (refuse to acknowledge) tags directed at them, in which case whoever tried to tag them must find someone else. The conversation goes: "tag", "sorry, no, I'm already leaving", "curse you, fiend!".
- Eject all non-keyholders from the building and lock up / set the alarm. This might also require checking the toilets, turning off lights or appliances, and that kind of thing, in which case have a checklist at the exit reminding them what to do.
The basic trick here is just to encourage keyholders (or everyone, if applicable) to consider locking up today to be an important task that has fallen to them unless they pass it on to someone else. OK, so someone might still forget, but at least they got a reminder on that day (not in a memo or company meeting six months previously), and at least checking whether you're the last to leave is a routine activity even for (some) people who normally are not the last to leave. And the person left locking up hopefully won't be someone who's forgotten how to set the alarm, because they have an opportunity to ask any questions they need to when they're tagged.
Typically the tag isn't arduous, since people will tend to tag those who work near them. Relatively few people actually have to search the building.
Note that the exchange of words "tag", "OK" is superior to just checking if anyone else is still there, since without interaction it's possible for two people each to observe that the other is still present. Then whoever leaves last doesn't notice the other one leave just before they do, but after they've established "I don't need to lock up".