Ever have someone share a piece of information in confidence and ask you not to tell it to anyone else—then you spilled the beans anyway? Of course you did! You're human. Some of us are better at keeping secrets than others. In order to understand why—and what makes the temptation to break the silence on others' secrets run so high—you first need to understand the psychology of secrecy itself.

A secret is any piece of information that's intentionally hidden from someone else. There are three main reasons why someone—or an organization like a company or country—would want to keep a secret.

One is that the person gains a strategic advantage from having information that other people don't have. Richard Nixon and Henry Kissinger kept quiet about their initial contact with the Chinese government in the 1970s in order to avoid backlash from Congress. Similarly, companies often keep their employees' compensation information secret to avoid candidates using it during salary negotiations (although this is beginning to change in some quarters).

The second reason is that the information would have negative consequences for the secret holder if it were more widely known. People engaged in illegal activities hold these kinds of secrets for obvious reasons.

The third is that the information would have negative consequences for other individuals if they found out about it. An obvious example is a surprise party, where the surprise would be ruined if the person being surprised learned about it ahead of time.

There are business cases in which this kind of secrecy can be valuable as well. Earlier this year, Kraft removed artificial colors from its macaroni and cheese mix, but it kept news of that change under wraps for three months after rolling it out so it wouldn't bias consumers' sense of taste (which can be affected by expectations). As Kraft anticipated, people didn't notice any change in flavor, and so the company launched an ad campaign to let people know about the switch well after it happened.

When you have a piece of information that's being withheld from other people for any of those reasons, it takes a certain amount of mental effort to keep it secret. You have to pay a lot of attention both to what other people already know as well as to whether they're allowed to know the secret information, too.

This mental effort can be a problem in casual conversation, where it's easy to let a piece of information slip unintentionally. Our minds have a limited capacity to process information. So if you're engaged in a complex discussion, it may be difficult to keep track of what you're allowed to say and what you aren't, which can lead you to divulge information you shouldn't.

The most difficult secrets to keep usually aren't about good news—they're the ones in which you become privy to a piece of information that has negative consequences, either for the person with the secret or for someone else. The simple reason why is that this type of secret creates social tension. In your mind, if other people had the information that you possess, they would see the world differently than they do now—probably with a certain degree of shock. The truth is that it often feels good to elicit a reaction from other people when you tell them something, even if it isn't something positive.

That tension creates the same desire you feel to share a joke you've just heard with people you don't know. And it's akin to the urge you feel to post on social media about a new product or movie or musician you've just come across that your friends haven't heard about yet.

So how can we resist the temptation to divulge confidential data? Start by revising, or at least expanding, your idea of honesty—which you can do without compromising your integrity (many of us unwittingly conflate these two things).

A final factor that makes secret-keeping so difficult (especially where others' secrets are concerned) is that avoiding telling others often requires lying overtly or by omission. People lie all the time in small ways, but telling a lie to protect someone else's information can be uncomfortable: We feel we're being willfully dishonest—which, technically, we are. The very act of keeping a secret is forcing you to transgress one of your core values, which ratchets up the psychological pressure that's already involved in keeping confidences.

Philosophers have spent centuries contemplating the ethics involved in situations like these, but in the end, it's important to recognize that not all secrets are bad. Without tipping too far in the other direction (where moral relativism resides), it helps to remember that in many cases, the advantages of withholding information can be high, while the costs of doing so (for you or others) are slight. Holding back information that might bias someone's opinions may also have benefits—even for the person who's being kept in the dark.

On the other hand, when you're asked to keep a secret that might otherwise get someone in trouble, you should think carefully about how you want to be involved in that situation. In many cases, these secrets get more damaging the longer they remain hidden—which can put your integrity at risk anyway. You may not choose to be the one to reveal the secret, but you can make it clear that you aren't willing to lie explicitly on someone else's behalf.

Let context decide which secrets you keep, otherwise your psychology may end up deciding for you.