SAN FRANCISCO — Facebook has been fighting for months the perception that it did not do enough to protect people’s privacy. On Thursday, the company said it had again failed to keep the information of millions of users private.

As many as 14 million Facebook users who thought they were creating private posts last month that only a small group of friends could see were, in fact, making public posts that anyone could view.

Facebook blamed a software bug for the problem. The company did not say how it had found the bug, or how it knew the problem was limited to 14 million people.

In a statement, Facebook said the bug affected users from May 18 to May 22, while the company was testing a new feature. By May 27, the company had changed the affected posts from a public setting back to a private one.