Here's how it works (as far as I understand - this applies to Edexcel maths for sure, and I think the other exam boards are the same).
You are first given the highest grade possible at A-level, but using the smallest amount of UMS points, subject to the following regulations:
P1, P2, P3 (or C1, C2, C3) MUST be present and at least one applied module at higher level must be included (e.g. D2, S2, M2 or above).
This usually means that your worst applied module marks go with your high P1, P2, P3 marks to make up an as-low-as-possible A for A-level maths. 480 / 600 UMS is an A grade, and the computer will automatically get as close to this boundary as possible, with the above provisors.
For A-level further, another 6 modules are required:
P4 and P5 (or FP1 and FP2 OR FP3) are required, along with at least 2 applied modules at higher level (M2, etc...) or at least 1 applied module at higher level plus P6 / FP2 or FP3.
This usually means that your best applied module marks go with your low P4, P5, P6 marks to make up a high-as-possible A for A-level further.
If you have 6 modules left over (only 6 - no fewer will do) then you can get a qualification in Additional Further Maths, but it doesn't count as an A-level, and you can't get points from it or have it included in offers. I think it's more gloating rights.
The upshot of this is that if you're taking F. Maths A2, you can be almost entirely sure of an A grade at A2 maths, as that's the computer's priority. I think this would even go as far as getting you an A at Maths A2 and an E at F. Maths A2, but I'm not entirely certain.