Once, Jesus said this:
Let your light shine before others, so that they may see your good works and give glory to your Father who is in heaven. Matthew 5:16
In the same sermon, Jesus then said this:
Beware of practicing your righteousness before other people in order to be seen by them, for then you will have no reward from your Father who is in heaven. Matthew 6:1
Notice the underlined parts? What’s the deal? Are we to let our light shine or are we to practice our righteous acts in secret for only God to see?
The Answer: both.
John Stott explains:
At first sight these words appear to contradict his earlier command to ‘let your light shine before men, that they may see …’. In both verses he speaks of doing good works ‘before men’ and in both the objective is stated, namely in order to be ‘seen’ by them. But in the earlier case he commands it, while in the later one he prohibits it. How can this discrepancy be resolved?
The contradiction is only verbal, not substantial. The clue lies in the fact that Jesus is speaking against different sins. It is our human cowardice which made him say ‘Let your light shine before men’, and our human vanity which made him tell us to beware of practising our piety before men. A. B. Bruce sums it up well when he writes that we are to ‘show when tempted to hide’ and ‘hide when tempted to show’. Our good works must be public so that our light shines; our religious devotions must be secret lest we boast about them.
Besides, the end of both instructions of Jesus is the same, namely the glory of God. Why are we to keep our piety secret? It is in order that glory may be given to God, rather than men. Why are we to let our light shine and do good works in the open? It is that men may glorify our heavenly Father.
(Taken from The Message of the Sermon on the Mount, p. 127)