How you account for your bad debts will depend upon whether you use the cash basis or the accrual basis of accounting. If you use the cash basis, you recognize income only when a payment is received; bad debts are not a problem because you simply never record the income that you were expecting to get.
If, like most businesses, you use the accrual basis, the process is a little more complicated. It's complicated because you actually accrue a bad debt when you sell your goods or services on credit to a customer who does not pay you. You must recognize the income from the sale at that time, but you won't know that the customer did not pay until you've exhausted all of your collection alternatives. Since this can take a year or more to determine, you often won't know that a past-due account is a bad debt until a later tax year. Thus, you may be in the position of recognizing (and paying tax on) income that you never actually receive, and not knowing this until a later tax year.
Why does a bad debt accrue when the goods are sold? Well, you offer credit primarily to increase sales. You are willing to accept the risk that a few customers might not pay you, in order to gain sales from customers who simply need more time to pay. In order to accurately determine your costs of doing business over a given period of time, you have to match your accrued bad debts during the period against the sales they help generate.