How does retained profit build up?
Each year a company makes a profit, pays Corporation Tax on it, and decides how much of what is left to pay out as dividends. Whatever is not paid out is added to retained profit. A loss, or a dividend larger than the year's profit, reduces it.
It is the running total from the day the company was formed, which is why it is sometimes called profit and loss reserve or accumulated profit. It sits in the equity section of the balance sheet, alongside share capital, and together they are what the shareholders own.
Its main practical use is that dividends can only be paid out of it. A company with no retained profit cannot lawfully pay a dividend, however much cash happens to be in the bank.