Do megapixels matter? Yes, but they are only one aspect of what goes into a photograph. So while they are important, there are several other considerations that are equal to, or more important, when trying to get the best photograph. The size of the image sensor itself is more important than the pixels.
If an image is out of focus, for instance, it will remain out of focus no matter how many megapixels you have. If there is a big dust spot on your lens, it will still be there regardless of the megapixels. Some have compared megapixels to calories. They measure how much information can be stored, but do not measure the quality of that information.
The image sensor is what makes the photograph. It collects photons – which are light – which are then used by the camera to produce an image. The image sensor has pixels on it that store information, and in fact there are millions of them, which is what a megapixel is – a million pixels.
So if your sensor can store 10 million pixels, that is better than 2 million pixels, right? Maybe, or maybe not. Some camera makers – and even cell phone makers – promote the idea that their camera must be better because it has more megapixels. But if you have a lot more than you need, you aren't using them anyway and they can become a hindrance. The more pixels you have, the larger your image can be and still look like an image.
One advantage of having more megapixels is cropping. With more megapixels you can crop an image more without losing image quality. But defining your image while shooting it is a skill you should develop, and rely as little as possible on cropping to get the images you want.
If you are sharing pictures on Facebook, emailing pictures to friends, or using any other social media platform, one megapixel or even less is all you need. Often one half of a megapixel is fine, and anything over 1.5 is a waste. Your image will not get a lot better if you post a 20-megapixel picture. The disadvantage here is that megapixels take up space. A larger megapixel image will take longer to upload and will take up more storage space. Many programs downsize your photos anyway, and that can make the overall image quality suffer.
Megapixels become more important when you print an image on paper, and the number of pixels determines how large that print can be. You may notice that on your camera you can set the resolution; there are numbers like 2,400 x 3,000, which is giving the dimensions of your image in pixels.
For printing purposes, multiply the dimensions of your print by 300 to get the needed pixels per inch, and then divide that by one million to get the number of megapixels needed. An 8 x 10 photograph printed on paper requires 7.2 megapixels, which is 2,400 x 3,000 divided by one million. You may make a 4 x 6 print with 2.2 megapixels, while a 16 x 20 picture would take 28.8 megapixels.
Megapixels are used to store information in your camera that will make an image, so you need some. What you will be using the image for is the bottom line in determining what you need, and anything more than what you need is just taking up extra space.