If your laptop works perfectly on the charger and shuts off instantly the moment you unplug it, the charger and the laptop are almost certainly fine. The battery is the problem: it is either dead, disconnected, or not being detected.
A laptop that dies instantly when unplugged is running entirely on the adapter. The battery is contributing nothing: either it holds no charge at all, it is not connected, or Windows cannot detect it. The diagnostic path is the same as for a battery that is not detected, with the battery health report as the decider.
powercfg /batteryreport, then open the report and compare Design Capacity with Full Charge Capacity. A battery holding a small fraction of its design capacity, or one that shuts the laptop down with charge still showing, has reached the end of its life.In most cases this problem ends with a battery replacement. A battery that dies instantly on unplug has usually lost almost all of its capacity, and no driver or setting brings that back. Buy a genuine replacement from the laptop maker when you can: cheap third-party batteries are a common source of repeat problems, and a battery that is three or more years old is a prime suspect. If the laptop is still under warranty, contact the maker first. On a sealed laptop, replacement means opening the case, so have a repair shop do it unless you are comfortable with that.
My laptop works on the charger but dies instantly when unplugged. Is the charger broken? Almost certainly not. If the laptop runs fine on the charger, the charger is delivering power. The battery is the part that is not holding any charge. Check the battery health report to confirm.
Can a dead battery damage my laptop if I keep using it plugged in? A dead battery is usually harmless to keep using plugged in, but a swollen battery is not: stop using the laptop and get it replaced. A dead battery also means any power cut shuts the laptop off instantly, so save your work often.
How long should a laptop battery last? Most laptop batteries are rated for around 300 to 500 full charge cycles, which works out to roughly two to four years of normal use. After that, capacity drops noticeably, and a battery holding 60% or less of its design capacity is due for replacement.
Laptop Battery Not Detected · Laptop Plugged In, Not Charging · Battery Replace Warning · Battery Health Low