Scripture presents two different kinds of righteousness.

Vertical Righteousness

Vertical righteousness (also called positional righteousness) is the righteousness between us and God. 

One cannot earn this righteousness but only receive it through faith. Luther called it an “alien righteousness.” Luther didn't mean that it comes from Mars; he meant that it comes to us from outside ourselves. We can't produce this righteousness. We are dead in sin. So Christ obtains this righteousness for us. Jesus' perfect life, death, and resurrection secure for us an eternally perfect standing with God.

Vertical righteousness is therefore a passive righteousness –– we don't earn it, it's a free gift we receive through faith in Christ at the moment of our conversion.

Scriptural examples:

For our sake he made him to be sin who knew no sin, so that in him we might become the righteousness of God.(2 Cor 5:21).

“And to the one who does not work but believes in him who justifies the ungodly, his faith is counted as righteousness” (Rom 4:4-5).

“. . . that I may gain Christ and be found in him, not having a righteousness of my own that comes from the law, but that which comes through faith in Christ, the righteousness from God that depends on faith(Phil 3.8-9).

Horizontal Righteousness

Horizontal righteousness (also called practical righteousness) is the righteousness between us and our fellow man. 

This is an active righteousness where we serve our neighbors in gentleness and love. 

Scriptural examples:

“Be completely humble and gentle; be patient, bearing with one another in love” (Eph 4:2).

"Let your conversation be always full of grace, seasoned with salt, so that you may know how to answer everyone" (Col 4:6).

“Make sure that nobody pays back wrong for wrong, but always strive to do what is good for each other and for everyone else” (1 Ths 5:15).

How They Relate

Many Christians (and pastors) don't know there are two kinds of righteousness and so they mix the two together, which causes much anxiety/self-righteousness. We must instead keep them separate. As Egon warns in Ghostbusters: "Never cross the streams!" 

This is critical.

Our horizontal righteousness never effects our vertical righteousness. We've been gifted Jesus’ perfect righteousness by grace and can neither diminish it nor improve upon it. EVER. It's permanent. 

Therefore, our good works don't merit us favor with God and our bad works don't remove God's favor from us. Horizontal righteousness then is not for God's benefit. How could it be? In His eyes we already have Jesus' perfect righteousness! 

So what's the point of good works? 

Luther: “God doesn’t need our good works, our neighbor does.” Horizontal righteousness is for our neighbor's benefit, that he might see our good works and worship God (Mt 5:16).

BUT! Though the horizontal never effects the vertical, the vertical has a profound effect on the horizontal. The kind and gracious way Jesus treated us will naturally have a positive impact on the way we treat our neighbors. 

"But by the grace of God I am what I am, and his grace to me was not without effect. No, I worked harder than all of them—yet not I, but the grace of God that was with me" (1 Cor 15:10).

For Further Reading

-Good News for Failures