uncontrollable shutdowns

The problem exists since today (or eventually yesterday).
This morning, I had the feeling that the displayed battery charge percentage was unusual low.
During commute, it suddenly shutdown, restarted several times, broke down several times.

What do I know?
* It seems as if the displayed percentage is not correct. Before one shutdown, it showed 12%. When I connected the charger, it immediately went to 88%.
* Breakdowns happen at irregular charge percentages, 15%, 55%, 68%, ...
* No breakdowns when using during the charger is connected, only when battery only.

So, what do you think is happening here? My device with the first battery is nearly three years old.

Time to replace the battery. The problem is given the age of the phone, you may not find any fresh ones. Batteries still age while sitting on the shelf, and will have decreased performance if left sitting long enough. That means even if you buy a new one, it could be old stock with decreased performance already. It'll be a crap shoot on getting a good one.

As others have indicated it's probably the battery. It would be better to get something newer than to replace the battery even though the 5X was a fairly solid phone. There are lots of great deals out there in the new and used market.

I remember someone baked the motherboard on a G4 in an attempt to soften the solder. I think it helped but it didn't last.

Usually those issues are due to incorrect solder in the first place, or some other design flaw, which makes any repair attempt temporary. I remember baking a laptop graphics card a few times, and it never lasted.

I remember someone baked the motherboard on a G4 in an attempt to soften the solder. I think it helped but it didn't last.

Originally Posted by Mooncatt

Usually those issues are due to incorrect solder in the first place, or some other design flaw, which makes any repair attempt temporary. I remember baking a laptop graphics card a few times, and it never lasted.

They gave me another Nexus 5x under warranty at that time but that soon failed and was told to buy a motherboard from lg but I was way past the phone at that time .

Thank you guys for all your answers. I guess, I will try to replace the battery - first time I try something like that - knock on wood. If it works - fine. If it doesn't work - not so nice - but c'est la vie and welcome Pixel 3a.

OK, I have bought a new battery. Careful, there are batteries out there sold as Nexus 5x batteries which do not have the same 2700mAh, some have 2300, other forgot.

With the help of several guides on the web, I was able to replace the battery. It took some time to open the phone. It was the first time I did it and I was afraid to break something.
The only real problem was to remove the old battery - the adhesive was REALLY strong. Comments of users on ifixit at that step said "don't use heat, use a spudger made from an old credit card". That worked for me but it was still a struggle.
Anyway, put the new one in, started and - run into that 50% problem "Battery status is always shown as 50%". Advice on the web was, disconnect the battery and blow the connection parts clean.
Reopening this time was very easy, following the advice, closing - and the battery is now at 75%. Seems to work.

It was the battery because even with a not-fully charged battery, I can use it again. Thanks.