This idiom is used when one gets their hopes up for something that has not yet materialised. For example, if a farmer counted how many eggs he had and assumed they were all chickens, he may be mistaken on the final number when the time comes. The farmer should wait until every egg has hatched and he can see which ones have formed into chickens and which have not. This way, he is certain of the final number of chickens. In other words, if someone assumes something before they are certain of it, they could find themselves mistaken.
The man redecorated his entire house before he found out if the company were giving out the Christmas bonus this year or not. He really shouldn’t have counted his chickens before they hatched.
The woman uprooted her life and moved 500 miles away from her home, hoping she would get a job in a company there. She definitely counted her chickens before they hatched. She’ll be in a tough situation if she doesn't get the job.