That is both an easy and complex question, so let’s do easy first.
As a rule, in the United States the terms lawyer and attorney are interchangeable.
Now for the hard answer. It’s hard because we have to go back a bit in history to understand the distinctions. The term “lawyer” was generally used to refer to any person who has studied and been trained in the law. The lawyers of the early US nationhood are a good example. Someone like John Adams or Thomas Jefferson were not only leaders of the American Revolution but they also were lawyers.
An interesting note on Adams career is that he actually provided a learned, principled and successful defense of the British Soldiers accused of crimes arising from the “Boston Massacre.” His reason was the same that many criminal defense attorneys cite today for their own careers. Every person, no matter how they are seen by the general public, deserves a zealous and competent defense (something we now find in the 6th Amendment of the Constitution).
As education in the US improved, and law began to become its own discipline, the term attorney at law (also attorney-at-law) was created around 1768. For a short time there was an effort to distinguish to two terms. The lawyer was one who studied and graduated after studying law, however, they were not necessarily seen as someone who had passed the bar; therefore they did not “practice law” before a court.
Even today we see that one can graduate from an American law school, thus becoming a lawyer, but not passing the bar exam. Without the passing score on the bar exam one can’t be admitted to practice law in the jurisdiction (state or federal).
The attorney at law, which was later shortened to just attorney, was used in some instances to mean a professional who is qualified to give legal advise and to represent a party in court.
Eventually, the early form of the law degree (which was considered a professional degree much like that for the ministry or medicine) evolved to a point that it would require a much higher level of education in order to be reasonably qualified.
Today, the terms attorney and lawyer are used interchangeably, mostly because the need to distinguish the right to practice law became so well defined with the expansion of the individual jurisdictions judicial system and also because the qualifying degree today to sit for the bar exam is a professional doctorate degree; usually the Juris Doctorate or JD.
There are still those who graduate from law school but never sit for the bar exam. The law degree is an excellent degree which can be used in many areas of business and government work other than the practice of law. Thus, the concept that one is a lawyer by virtue of the law degree still exists, it is just not enforced at enthusiastically as in the 19th and early 20th centuries.