The idea of an "atomic bomb" — a bomb that somehow used the immense power of nuclear reactions for its explosive force — was first discussed in the early 1900s after the discovery of radioactivity. The term "atomic bomb" was coined by H.G. Wells in 1914, in a science-fiction book. Scientists were decidedly skeptical of this because as of that point, while it was known there was indeed a lot of energy locked up in the nuclei of atoms, there was no viable way to let it out.
After the discovery of the neutron in 1932, the Hungarian physicist Leo Szilard hypothesized that if you had a nuclear reaction that was started by neutrons, and also released neutrons, that you could set up a chain reaction that would rapidly release a lot of energy very quickly. But this was still an "if" situation: he did not have a candidate reaction, and this was not taken seriously by any other scientists, because it was entirely speculative.
In late 1938, a team led by Otto Hahn and Lise Meitner discovered that bombarding uranium atoms with neutrons caused them to split — "nuclear fission." This was scientifically very interesting and news of it spread globally within several weeks. Szilard heard this an immediately wondered if uranium fission released neutrons, and whether it could be the candidate reaction for his chain reaction. He was probably the first person to make that jump, but not the last: other scientists quickly made the same idea. By late 1939/1940 scientists in Germany, the UK, France, the USSR, and the USA had written to their governments suggesting the possibility of nuclear weapons.
At this point you start to get into an idea of an atomic bomb as being a real possibility. It took a lot more work to confirm that it was actually possible, and to narrow down the conditions of possibility (you need a very specific type of uranium, you need it in the right quantities and geometry, you need to understand what kind of reaction you are doing, etc.). By 1942 scientists in the US were confident-enough that it could be done (after looking into the possibility for several years) that they were willing to suggest to the US government that they could indeed be built in a short amount of time. The Manhattan Project was created, at immense cost and difficulty, and did develop nuclear weapons by the summer of 1945.
The above leaves out many scientific and political twists, turns, and details, and is just meant to give you a rough sense of timing, as well as the difference between the idea of a device and its practical realization. The standard reference for the development of the scientific preconditions for the atomic bomb is Richard Rhodes' The Making of the Atomic Bomb, and it is a good (if long) read.