This is a hotly debated issue, and you'll get lots of info with many opinions, but much of it is based on scant evidence. The standard line in the West is, Japan, through emissaries, quietly inquired about surrendering before EITHER bomb was dropped, perhaps as early as their defeat at Midway Island, but I'm not so sure about that. In any case, the U.S. held a hard line, requiring an "Unconditional" surrender. They would not accept any surrender conditions which left Japan with any conquered territory, or with any viable military strength. This is a pretty typical demand in a major conflict - the same was true of the Allied response to early German entreaties to end the war. We also wanted Japan's emperor to step down - not be arrested or anything, just "resign" as head of state. The Japanese government refused to accept the, to them, ultimate humiliation of unconditional surrender, especially the part about the emperor. Some military commanders urged their leaders to accept that, to save themselves from what was to come, but ultimately the political leadership refused, out of pride. They DID try to surrender under less harsh terms, of their own devising, which left some small bit of their pride intact. Facing defeat for the Japanese, at that time, wasn't just "embarrassing". It was completely opposite to their culture and military tradition. Only when the specter of more bombs literally wiping Japan off the map was made shockingly clear, did they capitulate.
America was in no mood to give them an inch, after the "sneak attack" on Perl Harbor, and all the bloody fighting in the Pacific over the next five years or so. Revisionist historians like to claim the bombs were dropped to "scare Stalin" in the Soviet Union, but President Harry Truman personally gave the order for both bombs to be dropped, and this wasn't a harsh, vindictive, evil man, willing to kill countless civilians just to play nuclear poker with the Russians. Though nukes are horrible, cold math shows those two bombs SAVED lives. Far more people - Japanese, British, American, etc, likely would have died if the war had continued to its end with "conventional" fighting. Some will say "no, that's baloney - the Japanese were going to surrender anyway, even if we never dropped the bomb!". But that's bullsh*t. If that were true, they most certainly would have accepted unconditional surrender after the FIRST bomb. But they did not. Still pride got in the way, and they couldn't accept unconditional surrender, not until the grim reality of repeated nukes hit the emperor and his staff full in the face.
And the idea that Japan was "dithering" about the Hiroshima report, not knowing if it was an American bomb, and not knowing how to react to it or whatever, is also bullsh*t. They knew, because we told them. Repeatedly.
Again, there are lots of twists and turns in this story, so don't just take my word for it. You can enter you question above into a google search and get tons of info to read.
I know it's not exactly a fact but I really like this opinion from Yahoo.