If you can't afford one, the court will appoint one for you. It sounds pretty simple, but it may be a bit misleading. You have the right to a lawyer, but in general you must pay for your lawyer yourself. They either are accused of a felony or, if accused of a misdemeanor, are convicted and actually sentenced to a prison term. Suppose that you are charged with a felony or a misdemeanor for which you could be incarcerated.
Indigence is determined by jurisdiction.
In general, if your annual income is less than a certain amount predetermined by your jurisdiction and you don't have other assets, you qualify for a court-appointed lawyer, or public defender. If you make more than that amount or have other assets, you must hire your own lawyer. You may be surprised to learn that you qualify for public representation. Even if you truly can't afford a lawyer, a court does not have to appoint an attorney to represent you unless you are accused of a felony or, if accused of a misdemeanor, you are convicted and actually sentenced to prison. When you go speeding down the freeway 15 miles per hour over the posted limit, you break the law.