The stomach walls have a lining that contains epithelial cells that secrete a protective layer of mucous and bicarbonate.
The mucous is pretty much the same stuff which lines our throat and nose. It sticks to the walls of the stomach to provide a physical barrier so the acid doesn’t touch the stomach itself. When the cells come into contact with acid, they secrete bicarbonate. Bicarbonate is highly alkaline and very effective at neutralizing acid. This combination of mucous and bicarb is so good at doing its job that when the stomach’s acidity level is high, like PH2, the stomach lining PH is around 7, or neutral.