Short answer: Switch to aperture priority mode, set your aperture to f/11 or smaller, and take a picture of a light coloured wall or clear sky.
If you see dirt or dust in the final image then this could be from the lens or the image sensor. If you have another lens to swap out then you’ll be able to narrow it down to the sensor or lens, or both.
Why Does This Work?
This trick works particularly well because the dirt or dust will look like dark specks against the light consistent background of a wall or the clear sky.
The reason it helps to use a small aperture, large f-stop, is because of how this impacts the angle of the light rays coming into the lens. When the aperture is narrow the light rays coming in are at a narrower angle and so the dust gets directly in the way and casts a shadow on the sensor.
When using a large aperture, e.g. f/1.4, the light rays are coming in from a much wider angle and getting behind the dust to an extent. This means it will not cast as harsh a shadow. At an aperture like f/1.4 you are unlikely to see any dust.
When is Dust A Problem?
Dust is particularly a problem when you are using narrower apertures so is more likely to be an issue for landscape photography. In general, any situation where you are using a smaller aperture because you want a large depth of field, or because the light is bright, then you are much more likely to have dust show up in your pictures.
Also, the same point applies about a light consistent background as we mentioned above. In landscapes, the dust is particularly noticeable in the sky or flat overcast clouds.
Fortunately this is easy to fix because it mostly shows up in plain areas without detail. I’ve used the Spot fix feature in the standard Windows photo app to remove most of these spots:
Here’s another example, I was taking a picture of the sunset. Even at f/11 this seems fine without noticeable dust:
Then I upped the f-stop to the max on my A6000 setup at f/36 to try and get sunbeams, a sunstar effect, and suddenly there’s loads of dust:
So How Do You Clean Your Sensor?
First try removing the dust with an air blower, then use a single use swab to really get it clean. Check out this great video from hikyletaggart for a visual guide:
You are not meant to use compressed air, as this has moisture in it, and you are not meant to use a microfibre cloth in case you drag dirt across the sensor and scratch it. But at least with scratching it, you don’t need to be too worried as your sensor should be scratch resistant and tough. Check out this video from Arthur R where he has to try hard to scratch a sensor: