Yes, counting cards are legal. This is just as legal as someone adding up their bankroll in their head as they play the game. When you count cards this is all you do, is add up the cards in your head and predict with precision what the next card will be.