Batteries are consumable parts that can fail because of a defect or they wear out through normal use. Sadly problems with MacBook batteries do exist. Symptoms like; MacBook switching itself off randomly or not lasting as long as it used to on a full charge, may indicate that your battery is near dead.
A lot of poor battery performance on MacBooks is down to a battery that is being asked to do too much and by a user who is not looking after it properly. Keeping your MacBook fully charged without use can permanently reduce the overall charging capacity, however keeping your MacBook fully discharged can lead to what’s called a deep discharge state, which will make it impossible to charge your battery fully in future.
To avoid either of it happening, try and keep your MacBook 50% charged, and shut it down once unused, rather than letting it go into sleep mode. If however, you do discover that your battery requires to be replaced you do have few options. Apple offers battery replacement service and prices are reasonable. There are replacement batteries available from a number of third-party suppliers if you do fancy saving money and doing it yourself. When buying battery be sure to buy only a genuine Apple battery as faulty batteries can explode as well as catch fire. Unfortunately, with most of the aluminium MacBooks Apple dropped the ability for users to be able to replace the battery easily.