Counting cards is not illegal, neither is it against the rules. But it is quite a complicated procedure so unless you’re an extremely dedicated and patient person, this is not the kind of complications you want to get into.