Your Mac will automatically go to sleep when you leave it alone long enough, but you can customize the sleep settings to your liking.
Apple's built-in Sleep app is free and tracks sleep duration, but there are other paid apps that have even more sleep tracking features.