Counting is a tough (and oft-ask about) topic.
It takes years of experience to be able to do this well.
This article is meant only to get you started with counting.
We will talk about counting only one suit. (Counting out an entire hand takes tons of concentration, and at least 10 years of serious play.)
Here is the main message: Think in terms of what is missing.
This is the opposite of the "1-2-3-4" approach. Most new players make the mistake of counting as the cards are played. For example, as declarer, they lay down an ace and everyone follows. They mentally think "1-2-3-4." They next lay down the king and LHO shows out (but the dummy and RHO follow suit). They now think: "5-6-7." They see 3 more cards in their hand and go "8-9-10." Etc.
This is a bad way to count. Get rid of this concept!
Consider this trump suit:
How many trumps are held by your side? 8. How many do the opponents have? 5. When you draw trump, just watch how they break. Does everyone follow to the first round? Good. (If not, they split 5-0 -- yuk!). Does everyone follow to the second round? Great! They split 3-2--there is only one trump left. If someone were to show out on the second round, then the suit was split 4-1. This typically makes life difficult, but at least you know they were 4-1.
Not only does this help you count the trump (or key) suit, but down the road, it paves the way for you figuring out other things about the distribution.
Try again with this holding:
Let's say the opponents lead spades and you had to use a trump early. No matter. There are still 4 trump outstanding (since your side had 9). When you start to draw trump, just observe if they are 2-2 or 3-1 (rarely, they will be 4-0).
What if you have to establish a side suit? Dummy has A7654 and you have K3 in your hand. Trumps have been drawn. You have lots of dummy entries to the diamonds. You want to trump diamonds in your hand and try to set up good diamonds in dummy. Think in terms of "what is missing." There are 6 missing. You'd like a 3-3 break. If they are 4-2, you still can set up a winner in dummy (the 5th round). You lay down the king and all follow. You play to the ace and all follow again. Great--they weren't 5-1 (or 6-0). So, what is the count? They are either 3-3 or 4-2. You will soon find out. Play a diamond from dummy and trump in your hand. Did both opponents follow? If so, the suit was 3-3 and there are two established diamonds in dummy. If not, they were 4-2. You will have to go to dummy and trump the 4th round to set up the 5th card in the suit.
Say you are in notump with this suit:
What will you need in order to take 6 tricks in the suit? Think in terms of what is missing. There are 5 missing. If they split 3-2, the suit runs. Lay down the K. All follow. Play a club to the ace. If all follow, you are home free. They were 3-2. The suit will run. What if someone shows out on the second round? They were 4-1. You will have to give them the 4th round of the suit. Hopefully, you have an entry to the long clubs to get back to enjoy the 5th and 6th round.
What about this suit:
You are in 3NT. You count 3 sure tricks and will have an extra trick if the 5 missing diamonds divide 3-2. If everyone follows to the first 2 rounds, you have an extra trick. If someone shows out on the second round, they were 4-1.
This all might seem trivial, but it isn't. Carefully read and reread the thought process. Watch how the missing cards split. Get rid of the "1-2-3-4" method forever!