I seem to answer the same question on the meaning of dpi values in image files over and over again, so I'm trying to summarize it all on this page.
There are several ways of representing image data in a computer, the two most dominant ones being pixel images and vector images.
Vector images are made up of geometric primitives like lines, circles or curves. They have the advantage of being resolution-independent. You can zoom in on a circle infinitely without losing quality because you can recompute its "looks" at every resolution with some math formula. Vector images can also be represented in a relatively compact way. For a circle, you'll only need its center and radius, plus maybe the color if that is of importance. However, certain images cannot be represented that way, like photos.
They belong in the other category, pixel images. Those are made up of a rectangular grid of color dots, the pixels. Such an image always has a certain pixel resolution, width and height. As an example, an image could be 1200 times 600 pixels large. The width is 1200, the height 600, and the image would have 1200 times 600 = 720,000 pixels. That's relatively much data, but photos can be represented that way quite nicely. Note that a circle can also be put into that 1200 times 600 pixel image. But that's a rather wasteful way of storing it, and if you zoom into that pixel image at some point it will look "blocky", with all the pixels being recognizable as large color squares.
All that was just an introduction to the topic that I am trying to explain, physical resolution. Coming back to the example image, what do the 1200 times 600 pixels mean in the real world? What is the image's size there, its physical resolution? There are two answers:
If you acquire an image using a flatbed scanner at 300 times 300 dpi, it means that for every square inch (2.54 centimeters) of the document which is being scanned the scanner will come up with 300 times 300 pixels. Dpi stands for dots per inch. Should the result be our 1200 times 600 pixel image, the original document was four times two inches large (1200 / 300 = 4 and 600 / 300 = 2).
However, if the image comes from a digital camera, there is no physical resolution to go with the pixel resolution of that image. You took a picture from reality, which does not have any specific resolution. So in that case, you cannot possibly determine the real-life size of those pixels. You may print that picture and choose 300 times 300 dpi as the printing resolution, and the printout will then be four times two inches large and probably look fine. But there really is no physical resolution attached to the original image.
Now let's talk about image files. Images get stored into files all the time, with popular pixel file formats being TIFF, JPEG, PNG, BMP and so on. Those formats always store pixel image resolution values like our width 1200 and height 600. They can—at least most of them—also store the physical resolution, in the case of the scanned image, 300 and 300. But that is optional, and for a reason, as we've seen; sometimes, that information is not available. Finally, some standard situations that keep confusing users: