It's usually done on special teams by the return team. And it's up to the team to decide who does it. Often it's the middle linebacker or safety, as those positions have the best view of all the players.
The main reason they count is player rotation. An example is the same 12 players don't play on punt returns all game, as others rotate in. The counting is to make sure someone isn't thinking it's their turn by mistake.
If it was the same 12 players on one of the ST groups it would be a lot easier to keep track. So if it was all the same 12 when they call "PUNT RETURN" on the bench there would only be 12 to know to go - where as in reality there are 14-16 players trained for each ST group.
For the CFL players, if they have 13 in the huddle, where the count will usually happen at the amateur level, they're already in trouble with a flag on the way unless they call for a TO which I believe saves them the penalty but I may be wrong on this as pro rules differ on many levels.
The officials count too of course. The Head Ref and the Umpire will count the offence and the three deep officials will count the defence and confirm with each other via a point to the cap or a clenched fist. If they count 13, you'll sometimes see them pat their flags to signal to the other official that they have too many men. If they count 11, they'll usually point a single finger towards the ground to signify they're a man short. It's not a penalty of course, if a team wants to play minus one that's their prerogative, but it can have implications for the number of line players.