On Sunday, Justin Timberlake tweeted a photo of himself clutching an envelope, the word “absentee” just visible above its edge. “It’s #TheLastWeekend to get out there and get involved! My absentee ballot’s in . . . make sure you GO VOTE on Tuesday!! Remember: NO voting booth selfies,” Timberlake wrote.

The warning at the end of the tweet is a reference to something the singer learned the hard way. Timberlake flew from California to Memphis, his hometown, to vote early in the 2016 presidential elections, and unwittingly became a case study in how ballot selfies, while popular, aren’t always, well, legal. Timberlake, standing in the voting booth at the time, took a selfie, with his ballot visible. The now-deleted Instagram post encouraged his followers to vote, but not before going viral, powered by fans who were worried the photo might get Timberlake in legal trouble (it didn’t).

In Tennessee, taking photos or videos in a polling location is against the law. It’s one of the many states where, according to a recent CNN analysis, various laws prohibit ballot selfies like Timberlake’s.

So, exactly how many states ban ballot selfies? CNN’s analysis suggests 18, but there are a few tweaks we’d make to their conclusions. CNN lists Massachusetts as a place where ballot selfies are fine -- but the secretary of the commonwealth told CNN that ballot selfies are illegal, even if there’s nothing they can do to enforce the prohibition.

CNN’s listing of Iowa as a place where ballot selfies are prohibited might not be quite right, either. In Iowa, laws still prohibit photos in booths, but the legal counsel for Iowa’s Secretary of State’s office told The Gazette that “you can take a ballot selfie, but only in a way that is not interfering with anyone else....be a good selfie taker and make sure you’re only taking a picture of yourself.”

Using CNN’s sweep of the laws as a starting point, we’ve updated our 2016 map to show where things stand now to the best of our knowledge. Some states have, since 2016, clarified their position specifically on the viral phenomenon — or passed laws allowing them, such as California. States marked “illegal” on the map are places where, by law, ballot selfies of any kind are generally prohibited, no matter how well those laws are enforced. States “somewhere in between” might allow polling place photos, or selfies with unmarked ballots, but have some prohibition that limits what you can and can’t share with others (for instance, a marked ballot). States marked “legal” generally allow ballot selfies, with varying degrees of enthusiasm.

In all, by our count, 20 states generally prohibit ballot selfies, seven are somewhere in between, and 23 generally allow ballot selfies.

“You cannot use your cellphone, pager, camera, and computer equipment in an early voting center or at a polling place,” Maryland says on the state Board of Elections' website. In Virginia, meanwhile, ballot selfies are generally fine, although you can be removed from a polling place (after voting!) if your use of an electronic device “hinders, delays, or disrupts the voting process.” There’s nothing legally preventing a ballot selfie in the District of Columbia, although officials there have historically discouraged them.

Even in most states where the photos are illegal, there’s little evidence to suggest that these laws are strictly and consistently enforced, making the matter even more confusing. .

Ballot selfies rose in popularity as social media wormed its way into every aspect of our lives, and their virality outpaced the decades-old laws tasked with governing them. As The Post has explained before, ballot selfies have found their legality parked right in the middle of a weird intersection between voter integrity and freedom of speech. One of the concerns driving the laws against them is the possibility of vote buying: Someone could pay voters to vote a certain way, and then demand a photo of a marked ballot as proof. And so, some states banned that documentation altogether.

In New Hampshire, a law prohibiting voters from sharing photographs of their ballot to let other people know they went to vote was struck down as unconstitutional in federal court. But in New York, a law prohibiting photos of marked ballots survived a court challenge in 2017. A judge ruled that the New York law was “narrowly tailored” to prevent fraud, as Reuters reported. There are also a few ongoing court battles.

In any case, you can always take a photo outside of the polling station with your “I voted” sticker.