How to calculations deviation on a magnetic compass and effect of it?
We think of the earth as having a grid of lines covering it, which re use for defining a grid-position for a place, and for using as the basis for angles for defining our direction to travel from one place to another. These grid lines are latitude and Longitude, but they are a purely-human imaginary idea, they do not physically exist.

The Earth does have a naturally-occurring magnetic field, which at the moment is coincidentally vaguely aligned with the lines of Longitude. And this magnetic field has the huge advantage that its direction can be sensed using some very special lumps of rock, ie with a compass.

Problem 1 - the magnetic field is not actually aligned with the lines of Longitude, so there's an error. This mis-alignment is called Variation (sometimes called Declination in American books) and it's a simple geometric difference between the compass pointing at one place versus pointing at another place; so the value of Variation changes depending on where in the world you are. And this is complicated by the magnetic field moving over time!

Problem 2 - you insist on mounting your compass inside a ship/vehicle/airplane which is made of meta or has large lumps of metal in it, which will push or pull the Earth's magnetic field as it passes through the ship/vehicle/airplane. This causes a directional error in your compass which is called Deviation - and this varies depending on which direction your vehicle is pointing, ie depending on where the lumps of metal are around your compass.

The acronym for working with all this is T-V-M-D-C ("True Virgins Make Dull Company"). So starting with a bearing that you measure from a chart in degrees True, you add Variation to get degrees Magnetic. Then you take into account your particular vehicle by adding in Deviation to get degrees Compass. If you fly degrees Compass, you will be flying degrees True, but you've taken into account where you are, when you are, what vehicle you're in a dn what direction it's pointing.

Simples!