I resign when I know that I could flip the board around and beat Magnus Carlsen. At that point, there is nothing left for me to learn from playing on.
There are times when I might resign early, and other times when I might resign late. In online blitz and bullet, for example, I often play to checkmate or one move prior, especially when my opponent is short of time. In a tournament game at the Spokane Chess Club a few years ago, my early resignation shocked my opponent.
Cambareri,M -- Stripes,J
1.e4 e6 2.d4 d5 3.Nc3 Nf6 4.Bg5 Be7 5.e5 Nfd7 6.Bxe7 Qxe7 7.f4 c5 8.Nb5 1-0
I had suffered long in a somewhat better French than this one against Michael several months prior to this game. My confidence in his ability to torture me for two hours and bring home the full point provoked my resignation. I went home to share a bottle of wine with my wife and watch some television.
In contrast, another game several years before this, I fell for a poisoned pawn on b2 and had to give up my queen for a rook. I played on until my opponent checkmated me with two queens. I did set one small stalemate trap a couple of moves before the end.
At the Sixth American Chess Congress, New York 1889, Joseph Henry Blackburne resigned early to Mikhail Chigorin.
Black to move
In The Book of the Sixth American Chess Congress (New York, 1891), William Steinitz commented, "Black's game was lost. Still the resignation is chivalrous at this point, for he could have held out for very long" (14).
It is courteous to resign when lost, but there is no rule stating that a player must do so. The determination that a player is lost may be subjective. Sometimes players resign because they have overlooked a resource. There are numerous examples in books of players resigning when the game was still equal.