Apple - Mid 2012 MBP shuts down claiming no power with charge at 30% or 40% or more
Your battery is shot.
A battery's life is determined more by age than the number of cycles. Yes, number of cycles do play a part, but the biggest culprit is age. In short, you have a 4 year old battery. A 4 year old battery that was never used is going to perform about as well as a 4 year old battery with 500 cycles.
MATH FINDS TOP CULPRIT AS LITHIUM-ION BATTERIES AGE
As far as what you are seeing, this is not an abnormal symptom. Your MacBook Pro has no sensor to be able to determine how quickly a charge will dissipate within the cell. All it can do is measure the voltage under load and calculate how much charge is left.
As your battery ages, there is a build up of the solid electrolyte interphase (SEI). This layer is what "transfers" the electrical charge from the chemical reaction. As this layer builds, the performance degrades. This layer continues to build from the time the battery is manufactured until the time it is recycled. There's no stopping it.
In short, your MBP is calculating that you have 30-40% of battery left; it's only a calculation as it cannot account for or measure the SEI layer buildup.
Just to provide you a reference, I am working on a Dell Precision M4300 laptop (installing FreeBSD). The battery reports 100% and healthy. If I unplug, I get about 30 seconds before the battery dissipates and the laptop turns off. So, I have the same symptoms you do, except it's happening at 100% charge. This laptop and battery are 8 years old so the behavior is not unexpected. What would be unexpected is if the battery held any charge at this point.
The Good News
It's pretty easy to fix. iFixit.com has an excellent guide: Battery and Trackpad. Disassembling MacBook Pro 15" Retina 2012-2015 and the prices are relatively low (less than $45 on Amazon).
Disclaimer: I have personally used two of these exact model batteries on MBP's and both are still running strong.
You battery is dying!
4 years is usually average when a battery starts dying.
I would personally take it to the Apple store, have them look at it. They will tell you if it needs replacing. I would just get it replaced at the Apple store, the price difference is not to much and you know you're getting a good battery.
Replace it ASAP, as there is a chance the battery will start to swell and damage other components in your computer.
If you can download Coconut Battery and give us a screen shot:
You can also: 1. Click on Apple logo at top left 2. Click on 'About this Mac' 3. Click on System Report' 4. Power on the left
You will then see a few lines related to battery information like this
Cycle Count:
Condition: