It’s New Year’s Eve. There I am on the dance floor – it’s teeming with people and there’s hardly space to breathe. Loud thumping music pierces my eardrums and I have no idea where my friends are.

Then, the guy next to me takes a misstep, spills an entire cup of beer down my shoulder. I gasp as the cold brew winds its way down my back. But he’s too drunk and the music is too loud for him to notice. Is this supposed to be fun? What am I doing here? I hail a ride to get out of there.

At home, after wringing out my shirt and getting ready for bed, I take a minute to pull up my phone and glance at my Instagram stories.

There I see the plate of chocolate cake from the dinner with friends that started the evening.

That was delicious. Next, we’re raising a glass to the New Year. That champagne was phenomenal. Then, we’re toasting at the bar. That was fun! Next, I see us grooving and laughing on the dance floor. Wow, that was a great time! Why did I leave such a fun party? We have to do this again next New Year’s Eve!

Wait! What just happened??

How did my perception of the night change so dramatically? I had unknowingly been influenced by the peak-end rule, a cognitive bias among a long list of shortcuts our brain takes in shaping our behavior and memories. The peak-end rule says we don’t remember experiences accurately. Rather, we tend to recall the highlights and how things end. By rewatching my Instagram stories at the end of the night, I reinforced the highlights from my night out. I didn’t recall the sucky stuff so I ended up thinking I had a great time. When in reality I was mildly miserable for most of it.

How does it work?

Our brains don’t have the capacity to remember everything. Evolutionarily, it makes sense for us to only keep the memories that most aided our survival. Remembering the most painful and pleasurable moments helped us avoid them or seek them out in the future.

For a caveman, finding a berry that made him sick was worth remembering more than a berry that was just so-so like all the rest. Therefore, we economize our memories by prioritizing two types of moments to create snapshot memories — peak moments and end moments.

Peak moments

We tend to recall the most intense events most easily. This applies to both positive and negative memories. For example, in one study, when Red Sox fans were asked to recall a game they watched, they tended to remember the best game that they had ever seen.

Think back to the last time you went to an amusement park. You probably remember the wild ride down the coaster or the amazing funnel cake you gorged on. Now think a little harder. You probably stood in line for 30 minutes for a ride that lasted all of 30 seconds and paid $9 for that funnel cake, but that’s probably not what first came to mind.

End moments

We tend to remember events differently depending on how they end. In a classic experiment, patients were asked to rate the pain of undergoing a colonoscopy as they endured it. The researchers found that the colonoscopies varied in duration and pain intensity for different patients. Then they asked patients questions regarding their memories of the experience.

Guess which of the two patients, Patient A or Patient B, remembered their procedure as more painful?

Since getting a colonoscopy isn’t the highlight of anyone’s day, one would expect that Patient A who got the procedure over with more quickly would remember it as less painful than Patient B who had a more drawn out experience. However, that’s not what the study found.

In fact, researchers found that duration did not affect the memory of how painful the procedure was. Rather, the peak intensity of the pain as well as the level of pain recorded during the last three minutes of the procedure were the biggest determinants of the memories people formed. That is to say, by ending the procedure with a lower pain intensity, essentially leaving the scope in people’s butts a little longer, made them recall the experience as less painful.

This study not only has profound implications for potentially life-saving medical procedures, but also applies to our everyday lives.

How to use the peak-end rule to your advantage

Now that we understand why and how this cognitive bias works, we can use it to our advantage.

1. End on a high note

To make better memories, always consider how you will end an experience. For example, in one study, researchers found that the order which people opened presents affected their memories of the occasion. People who opened the lousiest gifts first and worked their way up to something they loved, reported being much happier than those who opened the best gift first and had to work their way down. You can put this insight to use when planning a special event like a date or party. Reserve the best and most fun moments towards the end of the event so everyone walks away with warm fuzzy feelings!

You can also use the peak-end rule for your health. Researchers found that by ending an exercise at lower intensity, people were more likely to feel positive about the experience and were more likely to look forward to future sessions.

2. More peaks, more memories

Studies show we remember moments of intense pleasure, even if those moments are sparse, more fondly than experiences where we are mildly comfortable throughout.

If you’re a homebody, chances are you enjoy staying in on a day off. Trouble is, you likely won’t be making many fond memories while sitting on the couch even though you’ll be mildly comfy and entertained.

Rather, getting out there, even if it hurts, can create lasting memories if it leads to an intense payoff. Chances are, heading out to see a spectacular sunset with friends on a mountain ridge will stay with you for a lifetime, while you’ll soon forget the hours crammed in a car or the grueling hike to get there.

3. Small bursts will do

The peak-end rule also shows us we don’t need an experience to be long to make a positive memory. For example, planning a vacation, an intense ski day trip full of high intensity bursts of excitement, may make as many positive memories as a week away at some far off exotic destination with less to do.

The same goes for how we enjoy our meals. Researchers found people remembered small portions of their favorite dishes as fondly as eating larger portions. So if you’re watching your waistline, treating yourself to smaller portions of your favorite foods may help you avoid eating more than you need while still providing fun.

The peak-end rule serves a key evolutionary purpose – it helps us avoid devoting more brain capacity to memories we don’t need. Knowing about this cognitive quirk helps us use it to our advantage. By seeking out and crafting certain experiences, we can create better memories to collect over many New Year’s Eves to come.

Nir’s Note: This post part of a series on cognitive bias co-authored with and illustrated by Lakshmi Mani. Discover other reasons you make terrible life choices like confirmation bias, hyperbolic discounting and distinction bias.

This article first appeared on Nir & Far.