This core belief is something we were all conditioned to accept in our childhoods, and it's at the root of the narcissist's power over you:
"If you are good, you will be rewarded. If you do bad, you will be punished."
It's so easy to believe this idea because our entire upbringing trains us to connect good behavior with positive responses.
Our society — from schools, to laws, to social norms — is filled with messages along the lines of "as you sow so shall you reap." We're conditioned to believe that the more "rightly" we behave, the more likely we are to receive rewards and avoid negative consequences.
The narcissist, consciously or unconsciously, leverages this.
They, like most abusers, will do everything in their power to convince you that their behavior is your fault. Their outbursts, mistreatment of you, and cruelty are the "appropriate consequence" of the "horrible wrong" you've done them. (And they often actually believe this themselves, for an unexpected reason.)
The problem is that even if in the moment you know this doesn't add up, some part of you believes that if you could just get it right, the cycle would end. They would cease getting so upset. Their unkind treatment of you, their punishing coldness, all of it would stop if you could just be "good enough."
And they want you to believe this.

Whether consciously or unconsciously, they know that by keeping you in a state of anxiety over whether or not you are doing the "right" thing, they are maintaining their control. They are able to continue being the god of the relationship: the one who metes out justice by rewarding or punishing your behavior.
How can you break free?
In order to break free, you will have to accept something that most narcissists' partners have a hard time accepting: your "good"ness does not matter.
You do not have the ability to "make things work" by being a kinder, more attentive, or more accommodating version of yourself.

It does not matter how self-sacrificing you are.
It does not matter how intelligent you are.
You will never be clever enough, good enough, or giving enough to figure out the special code of "right" and "wrong" that will finally soothe the narcissist once and for all and put an end to their miserable and abusive behavior.
This is because there is no code.
The narcissist would intermittently abuse you even if you were a literal saint.
There is no path to peace here because the narcissist does not want the peace you are working so hard to create for the both of you.
You will have to give up.
Being good will not protect you. And that hurts. (It's also really, really hard to accept because the narcissist's "love" is one of the most addictive things you will ever encounter.)
But if you can accept this truth, a new path will open up to you: one in which you no longer have to be perfect to be lovable.
You will no longer have to micro-manage every little thing you do, because it will be OK to make mistakes. You will no longer have to walk on eggshells and hold your breath, because it will be OK to be human.
Beyond the sharpened razor path that the narcissist would have you walk lies a different path, not at their side:

The path where you are allowed to mess up, and sometimes shout when angry, and be in the wrong and still receive love.
This path is infinitely freer, safer, and filled with more genuine joy.
I promise.