iPhone 5S suddenly turns off at 30-40% of battery life
When I was a Genius at an Apple Store about two years ago, this issue was relatively common. Most likely this is a hardware issue with the battery itself, but there is a chance it could be a battery calibration issue. It's best to troubleshoot calibration first.

Calibration Issue

The battery itself keeps track of how much battery life it has, and reports this back to the phone, which it then displays on the screen for you. Sometimes, the battery may be fully charged, but the battery or phone instead reports a different charge percentage.

Fixing a calibration issue is relatively easy:


Use your phone until it completely runs out of battery power and shuts off.
Plug your phone into a charger, and leave it plugged in until it is fully charged. Ideally, do this overnight so you know to be sure it gets completely charged.


This process will tell the phone and battery where its lowest and highest charge points are.

Hardware Issue

If you continue having the issue, it is almost certainly an issue with the battery itself. If you have an Apple Store nearby, make a Genius Bar appointment there and bring your phone in. They can replace your battery there the same day, and it usually takes less than an hour.

If you don't have an Apple Store nearby, there may be an Apple Authorized Service Provider near you that can help. Go through the prompts at Apple's support site, and they will help you find a good option.