You can configure the HTC One M8 to automatically disable mobile data if the latter remains idle for too long. This can be achieved by enabling the Sleep mode of your phone, a feature which will help to both save battery power and reduce costs related to the use of mobile data.
In this FAQ you will learn how to enable the sleep mode of the HTC One:
Go to Settings > Phone > Power.
Toggle "Sleep mode - Turn off data connection during long period of activity" on