Retained Earnings is the accumulated portion of net income that is not distributed to shareholders. Because the net income was not distributed to shareholders, shareholders equity is increased by the same amount.
Of course, if a company loses, it is called retained losses, or accumulated losses.
Historically profitable companies sometimes have negative retained earnings. This is because they have cumulatively paid out more to shareholders than they reported in profits.
For example, in 2011, Microsoft had negative retained earnings. This does not mean the company lost more money than it made over the years. It just means it paid out more money than it earned.
If a company has negative retained earnings, investors should check the 10-year financial results. They should not assume that negative retained earnings prove a company has generally lost money in the past.
Of course, many companies with negative retained earnings have indeed lost money in the past.