It's per game.
Right click a game (or press Start in BigPicture/GamingMode), select Properties. Go to the Privacy tab, and there you can hide the game from everywhere but yourself. The game will only be visible in your own library when logged in, and people won't see you playing that game when you run it (you appear Online but not playing anything, your nickname in friends list remains blue). You also make the game invisible in your profile, both on the main page with the play time and on the full games list.
You can also do it before purchase, now every time you put a game in the cart you are asked if you wanna make it remain public or hide it.
Invisible only doesn;t show the notification, but play time is still counted on your profile. If you check a profile and you see the latest game's play time increasing over time but they offline, it means they invisible.