We just gotta know about pixels, and if any mystery, a short primer is here: What is a Digital Image Anyway?
Seriously, once we accept that pixels actually exist, then all this stuff is rather easy. It's all about pixels.
This page tries to be a quick summary of the digital concepts, about how things work. The answer to virtually any question about image size starts with one of these basics. To be able to use digital images well, we need this understanding.
The size of an image might be, for example, 4000x3000 pixels. The math is that this is 4000x3000 = 12 megapixels. Or, 4288x2848 is also 12 megapixels (rounded off). This is also the "resolution" of the image, indicative of the "fineness" of the smallest possible detail (a pixel). This is the first thing to know about any image, because this size in pixels is what is important for any use.
A pixel is just a color, specifically, the three RGB numbers of a color specification - which represent the color that was sampled from this tiny dot of image area. When the image is viewed or printed, each little dot of image area is shown to be that corresponding color. In that way, digital images are very much like mosaic tile pictures (but in an ordered grid pattern). Each little dot is a color, and our human brain puts them together to recognize an image in all those colored dots. If it is an ordinary standard 24-bit RGB image, the pixel data is one byte for each of the Red, Green, Blue components of the pixel, which is three bytes per pixel. So if 12 megapixels, then x3 is 36 million bytes of data (24 bits). That is simply the actual data size of any 12 megapixel image data, however you may see it compressed much smaller while it is in a JPG file (JPG file size is much smaller than the image data size, via JPG compression). But when that file is opened, it is full size again in computer memory, three bytes per pixel (24 bits). For other than 24-bit, and for the special interpretation of "megabytes", see more detail.
The size of that image data when opened in memory is in bytes of memory. 24-bit RGB images (8-bit color) is always three bytes of RGB data per pixel. So bytes is the "data size", but "image size" is always in pixels. Whereas, inches only refer to the paper where these pixels will be printed.
A JPG file is compressed to be maybe 1/10 this data size (roughly, can be very variable), while in the JPG file, but 12 megapixels opens again to 36 million bytes in memory. JPG uses lossy compression, which means we can specify High JPG Quality for a larger better file, or Low JPG Quality for a smaller worse file (when file size is more important than image quality). See JPG.
Printers print on paper which is dimensioned in inches, but video screens are instead dimensioned in pixels (there is no concept of inches in video systems). This difference gets our attention. These devices do NOT work alike. They both show the same pixels in their way, but the basic concepts are quite different.
The video screen size is dimensioned in pixels, and the image is dimensioned in pixels, and the pixels are simply shown directly. The video screen simply shows pixels one for one - one image pixel on one monitor pixel. For example, an image 800 pixels wide will fill exactly half the width of a 1600 pixel screen width.
Dpi and inches are unknown concepts (not used) in video systems, or in digital cameras. Digital images are dimensioned in pixels. The video screen is dimensioned in pixels. The camera sensor size creates the image to be its same size, dimensioned in pixels. The dpi value shown in camera images is merely some clutter in the file header, a separate arbitrary number which has not affected the pixels in the image file. Dpi is for printing, or for scanning. Otherwise, it simply does not matter what this number is, Until the time you actually print it on paper, when you will decide an appropriate value (see Scaling below).
When we show a huge image, larger than our viewing screen (both dimensioned in pixels), our viewing software normally instead shows us a temporary quickly resampled copy, small enough to be able to fit on the screen so we can see it, for example, perhaps maybe 1/4 actual size (this fraction is normally indicated to us, so we know it is not the full size real data). We still see the pixels of that smaller image presented directly, one for one, on the screen, which is the only way video can show images. When we edit it, we change the corresponding pixels in the original large image data, but we still see a new smaller resampled copy of those changes.
There is no concept of inches or dpi used in the video system. It does not matter if the monitor is a 12 inch screen or a 24 inch screen, if it is set to show 1280x1024 pixels, it will show 1280x1024 pixels. Both sizes show the SAME image, just at different sizes on the two physical screens. You might think you are showing your image to be, say 8 inches wide on your monitor, but it probably will show a little different on some other monitor of different size or different resolution setting. We don't all see the same size in video, it depends on the screen size (both pixels and inches). Especially for web images, we have no clue what monitor might view it. Yes, all of our 8x10 inch paper is the same size, but there is no concept of inches or dpi in any video system. Video shows pixels, directly. Really pretty simple (but different).
If the image dimension is 3000 pixels, and if printed at 300 pixels per inch, the image will cover 3000/300 = 10 inches on paper. The image contains pixels, but all of the inches are on the sheet of paper. Within a reasonable small range, we can print different sizes by just spacing the same pixels differently (or for a larger range, we could resample the pixels to be a different image size). The only purpose of the dpi number is to space the pixels, pixels per inch, on paper. We can change this dpi number at will, to print different sizes on paper, without changing any pixel at all (called scaling).
3000 pixels / 400 dpi - 7.5 inches of paper
3000 pixels / 300 dpi = 10 inches of paper
3000 pixels / 250 dpi = 12 inches of paper
3000 pixels / 200 dpi = 15 inches of paper
Or the other way, 3000 pixels / 11 inches = 272 dpi
If you print the image at home, from the image editor File - Print menu, the computer will use the dpi value in the file to compute the size of the image on paper. If it is 4000 pixels and says 180 dpi, it will try to print 4000/180 = 22.2 inches size. This is the only use for dpi in camera files (printing). Some print menus offer a way you can scale the size first however, to print a different size. If you scale this image to print 10 inches (to fit the paper), then it will scale to print at 4000/10 = 400 dpi (inkjets really cannot, but they try).
If you upload the image file to be printed somewhere, they don't ask dpi, they only ask what size to print the pixels. They will scale it for you. If you upload a dimension of say 2000 pixels, and ask them to print it 10 inches, you will necessarily get 2000 pixels / 10 inches = 200 dpi result. Most online printers have 250 dpi capability.
Scaling is adjusting the value of the dpi number in order to fit the image pixels to the paper size, for printing. Word definition: A scale is a graduated measurement, like a map scale, and scaling is creating a proportionate size or extent, in this case of pixel distribution relative to the paper dimension. Scaling is computing that 3000 pixels printed at 300 pixels per inch will scale to cover 3000/300 = 10 inches of paper. The pixels are scaled so the dimension fits the paper.
So in any existing image, the only purpose of dpi is about scaling the image size on paper, pixels per inch. And of course, that numerical dpi result should also be an acceptable printing resolution for good quality. Just saying, printing at 100 dpi will be pretty poor (but 3000 pixels will print 30 inches then). Also excessively high values like 500 dpi will be pointless, just wishful thinking (but 3000 pixels will print 6 inches then). Printer capabilities are such that we can expect best results around 250 to 300 dpi, so we supply sufficient pixels to print the size we want, for example, 2500 to 3000 pixels for 10 inches. See how easy this is?
Normally, our usual goal is that we try to print photo images at about 250 to 300 dpi. This is the capability of the printers (designed for the capability of our eye to see it). 250 to 300 dpi is good for our printers at home, and also good for printing services such as Shutterfly.com, Mpix.com, Snapfish.com, Walmart, etc. We adjust for the paper size by Scaling the image (setting the dpi number value to print that size). Or, if the image is much too large, we Resample it to be smaller, so that we can scale to around 300 dpi. We also need to crop it to the same shape as the paper. See Resize Images about Cropping and Scaling and Resampling, to fit and print the image.
If we print the image on our home printer, by selecting menu File - Print, the printer will honor the dpi number specified in the file, and will print the pixels at the size (inches) determined by the the pixel dimensions and the specified pixels per inch number.
(Pixel dimension) / (paper dimension inches) = pixels / inches = pixels per inch
If we send the image out somewhere to be printed, and specify "print this 5x7 inches", they will. They will necessarily ignore our dpi number, and will rescale the image to the necessary dpi number to print the requested 5x7 inches (to cover the 5x7 inches with the provided pixels). The printer machine only has capability in the 250 to 300 dpi range. If their scaled dpi number comes out higher than 250 or 300 dpi, it won't hurt, but it cannot improve the quality. You can upload your 12 megapixel images to them, but if printing 6x4 inches, then about 1500x1000 pixels is all that can help (250 dpi). I am being ambiguous about 250 vs 300 dpi, normally it won't matter much which we use (we are at limits), but both will print slightly better than 200 dpi.
However, changing this dpi number will cause absolutely no change at all on the video screen (unless resampling is also selected). Video is not concerned with dpi or inches. Video ignores any dpi number, and simply shows the pixels directly. No matter what number the dpi says, you will will never see any effect of it on the video screen, which simply just shows the pixels directly. See an example of that.
Printing paper also has a similar shape, and the same Aspect Ratio applies. For example, 6x4 inch paper is also 3:2 aspect ratio. If we print THIS image on THIS paper, it will fit - the shapes are the same 3:2 aspect ratio (3000x2000 pixels is quite excessive though, for 4x6 inches), and really ought to be resampled to about 1800x1200 pixels first (3:2), to about 300 pixels per inch size.
However, if we want to print this image on 8x10 paper, the paper shape is different (4:5 aspect ratio) than the image (3:2), and some of the image will be lost (cropped, outside the paper edge, off the paper - the shapes are simply different). Or we could choose to fit the tightest dimension, leaving blank white borders the other way (we hate that too). We had exactly the same issues with film, not necessarily the same shape as our paper, but digital methods are a bit different. Now, we need to do Crop and Resample and Scale for when printing this.
Video screens also have aspect ratio. Non-widescreen monitors used to all be 4:3, and HDTV wide screen is 16:9. This is equally important if we are trying to fill full screen, but we are more comfortable with blank space bordering our video images, than on paper.
But digital basics are all the same for all images, so after image creation, then it is a digital image, and pixels are pixels, and dpi is only used to control the size of the printed image on paper. Whereas video screens are dimensioned in pixels too, and have no use for any dpi number.
The camera will stick in some arbitrary dummy dpi number, just so some printed size can be shown. Camera brands vary in the dpi number they make up, but this value is a meaningless arbitrary number, confusing if we try to make any sense of it. There is NO CONCEPT of inches in the camera (just pixels). The camera can have no clue what size we might eventually print it. The image is dimensioned in pixels. We will change that dummy dpi number when we decide how we want to print it.
FWIW, I am saying dpi for "pixels per inch". I am aware it has always been called dpi. I am aware that nowadays, some instead prefer to say ppi for same thing. I am aware that printing devices have another second use for dpi, meaning ink drops per inch, including halftone screens. If interested or confused, see more details here.