I created two documents with same pixel dimensions (1280x768).
Document 1: 72ppi
Document 2: 300ppi
When I saved both in
.png, they have the same size on the hard disk. Why do I need PPI? Why can't I just use pixels?
Answering the specific points in the question:
...two documents with same pixel dimensions (1280x768)...
When I saved both in .png, they have the same size on the hard disk
Those aren't normal low and high res variants - what you have there, is two images that are identical, except that the low PPI thinks it's going to spread those 1280x768 pixels thinly across a large area, while the high PPI one thinks it's going to concentrate those 1280x768 pixels in a high quality print on a small area. But the important stuff - the data - is the same.
I'm guessing what happened here is, you changed the resolution in [something like] Photoshop leaving [something like] the 'Resample Image' box unchecked.
This means your image didn't actually change - it just changed how many inches of paper it thinks it can stretch those pixels over.
If you go back to the 300ppi original and scale it down again with "resample image" (or equivalent) checked, it should give you the more lightweight low-res file you expected.
If you'd had the 'Resample image' box or equivalent checked when you changed the resolution down from 300 to 72 to make the low-res image, it would have kept the size in inches or centimeters the same, and simplified the image so that each inch had only 72 pixels instead of 300. For example, If you had a business card design, 3.5 inches by 2 inches, 300 PPI, and you did this, it would still be a 3.5 inch by 2 inch business card, but it would have fewer pixels. It would be a smaller file and would print lower quality, on paper of the same size.
If the 'Resample image' box was unchecked, it would keep the 1250 by 600 pixels, and just calculate how many inches this could cover at 72 pixels per inch. It would be exactly the same image, just thinking it could print bigger because it thinks you're less fussy about print quality, so it thinks it can stretch its pixels further.
This number only recommends the "scale" when you are using a program that actually makes sense of it. These programs are used normally to actually print your document. Think of it as a Post-it saying: "Use this number, please".
It only "recommends" because you can choose to simply ignore it.
Let's think that you open the image on an image viewer and you want to print it. You could have several options when printing:
The first two options will simply ignore the PPI embedded in the metadata, the real printed size will depend on the actual paper size, orientation, margins, etc.
But the other two options will use the declared number in the metadata as a reference to calculate the print size.
Some other programs will use it to define an initial size when working with it, for example, a layout program like InDesign, but again you can simply ignore it and resize the image inside the program.
All this confusion comes from what I call "The Window of Doom" when exporting from Illustrator. Even if you originally defined your document to a specific pixel dimension (as your example 1280x768) this window can ruin your export.
The text is in Spanish but the idea is clear
This "default value" will give you an image of 2667x1600px instead of your original size of 1280x768px.
And this "default value" will give you a file 5333x3200px
But look how the original file was defined when created!:
The selection box defines this as an option for the raster effects, but the program actually it considers all the file to be that PPI!
Add that the archaic, obsolete, useless and misleading number 72 PPI as a resolution for web... How this windows handle the information and the export settings have no sense.
Some other programs have a different approach, simply let you know all the parameters of the export. Here is Corel Draw:
ppi just means 'when you display it, how many pixels are you cramming into an inch of real world space'. Higher ppi (density) means smaller area to stretch your pixels across.
As computer screens have a fixed set of pixels, based on your monitor, it will always display the image at the same size (1 pixel = 1 pixel) regardless of how big or small the ppi (density) is.
Typically screen is considered 72ppi (or 96ppi), but it really depends on your monitor, so ppi is only really relevant to print.
There is an awesome article on Wikipedia about this subject. https://en.m.wikipedia.org/wiki/Pixel_density But, as it has been said before, if your document is to be printed, choose 300ppi, but for the web and game development, 72ppi is suitable.
The best way to understand this is to suppose you have a photo to "blow up" or enlarge, and then when you enlarge it, you either have broad fields of .jpeg trash artifacts and it doesn't look very precise, or the human brain is saying "hey that's so simplified and smooth, where's all the detail?" So to sharpen it up for printing it as a giant poster, you would have to go in and manually add detail where you find it lossy. It's /kind/ of like a resolution, but 72 ppi would be a lossy version of 300 ppi.
Folks are saying it isn't necessarily lossy, and that's kind of sort of true because if you don't add any more detail to a 'blown-up' image, it will just look like a scaled-up image, but that can look either like blotch-y .jpeg trash, or at best "cartoon-ish," owing to the lack of complexity in the interstitial areas which previously had no data. So complexity always increases with scale, just remember that.
So a relatively decent 72 ppi, while fine when looking at your < 2'x2' monitor, will look more simplistic and primitive in print than a 300 and printed ppi. So either begin the work in 300 ppi and what you see is what you get, or transition it there and then go in and add the arm hairs. Does that make sense?
I'm not trying to say that either print or digital are more precise or complex, only that dpi (a printing term) and ppi (a CG term) are both relative to the actual physical size of the final product.
ppi is short form of pixel per inch, also called as dpi, dot per inch. Changing resolution, in this case 72 ppi or 300 ppi will change only document size. Document size is changed when we need some changes in image size going for printing. Total number of pixels remains unchanged and hence despite change in document size image size remains same. It is to noted that image size and document size are two different things.