Physical Appearance, Size, Build and Dimensions:
It is one of the main aspect in which they differ. Both have, different build material, S5 having a polycarbonate body, while the M8 has a aluminium unibody design. The S5 measures 142 x 72.5 x 8.1 mm, and weighs 145g, while the M8 measures 146.4 x 70.6 x 9.4 mm, and weighs 160g. For appearance, the M8 looks a bit sexier and has a solid build quality than the S5, but the preference may differ individually (light weight or awesome design). Still the M8 wins this case.
Display:
Both have the same screen resolution of 1920 X 1080 pixels, with the S5 having a slightly bigger screen (5.1 inches Super AMOLED with 432 ppi pixel density), than that of M8 (5 inches Super LCD3 with 441 ppi). And since both of them have the Corning Gorilla Glass 3 protection, This case can be considered to be tied!
Memory and processor:
Both have an internal memory of 16 GB with an microsd slot expandable upto 128 GB, and a RAM of 2GB. The processor used is also of almost same level [Qualcomm MSM8974AC(B) Snapdragon 801 chipset, and 2.5 GHz Krait 400 processor]. Both use the same Adreno 330 GPU, and hence this is also tied!
Camera:
The S5 has a 16 MP main shooter which can capture upto 2160 pixels video with 30 fps, while the M8 has a dual 4 MP Ultrapixel camera at the back with dual LED Flash, which can captures videos upto 1080 pixels @60 fps. The M8’s camera is of 2µm pixel size, which captures great images in low light, but still in daylight, the S5’s camera beats it easily. For selfies and video calls, the S5 has a 2 MP front shooter, while the M8 has a 5 MP. S5 wins this with few points.
Battery:
The S5 has a Li-Ion 2800 mAh replaceble battery with a talktime of upto 21 hours, while the M8 has a Non-removable Li-Po 2600 mAh battery with a talktime of upto 2o hours (in 3G). Though the S5 has a greater battery and the user replaceble would be a good option, the M8 wins the case since its battery will not deceive you for a longtime. M8 wins this case!
Other features:
Both run in Android 4.4.2 Kitkat, but the HTC Sense v6 UI of M8 is is considered to be better by the users than the TouchWiz UI of the S5. The S5 has several useful features such as Heart rate sensor, Air gestures, Smart Stay, Smart Pause etc, while the M8 has stereo FM radio B-) The M8 is healthier, since it has SAR lower than that of the S5. Almost all the data connection features are same, but the M8 has inferior USB 2.0 against that of the S5, which has USB 3.0. The M8 produces better sound than that of S5, with its built-in-amplifiers. The S5 has some more awesome features such as Fingerprint sensor and Dust and water resistance (IP67 certification), which the M8 lacks.
Conclusion:
Picking a winner among the two may be really difficult, but its upto the user what he prefers- FM radio or Gestures, Aluminum body or IP67 certification, removable or a longer lasting non-removable battery. The M8 is usually cheaper than the S5, but HTC is slower for providing updates! The verge is that you should decide what you want! Good luck!