I'll try to explain in detail, hopefully it will be clearer to you.
Before anything else: YOU DO NOT NEED TO TRAIN A POKÉMON TO LEVEL100. All methods for optimizing a Pokémon's stats can be done without going to level 100 (you can optimize without gaining a single level, actually), and link battles set levels to 50 anyway. You also don't really need to breed a perfect IV specimen: read on for details.
I'll explain everything about stats to get to what you want to know.
0. Base stats
The base stat value is a number for each stat. All Pokémon of the same species have the same base stats, and they tell you, in general, which stat is high or low for that species, and how it compares to other species. You can't see them ingame, but you can find them on Bulbapedia, the Pokémon wiki. Roughly speaking, a Pokémon's stats at level 50 will be about the same as its species' base stats (except HP, it's calculated differently).
For example, Cinderace has base Speed 119, while Inteleon has base Speed 120. Both of these are high, so you can usually expect both of them to be faster than an opponent, and Inteleon will usually be a bit faster than Cinderace. Copperajah on the other hand has base Speed 40, so it's usually very slow.
1. EVs
Effort values, also called EVs or base points, are points collected by a Pokémon as it is trained that slowly raise its stats. They model hard work and exercise. Freshly caught Pokémon have 0 EVs, and they gain EVs by defeating other Pokémon in battle, or by drinking vitamins like Protein or Calcium. EVs affect stats by scaling them up so that at level 100, a Pokémon gets +1 point in its stat for every 4 effort points it has in that stat. (At level 50, you see an increase of +1 for every 8 EVs, at level 25 for every 16 EVs etc.). You can get maximally 255 EVs in a single stat and 510 in total, so indeed, you can maximize 2 stats, giving each 255 points for an increase of 255/4 rounded down = 63 at level 100. You would see this as 31 additional points in the stat at level 50, or as the stat being higher by 6 at level 10, by 3 at level 5.
Vitamins like Protein add 10 EVs to a stat - so to maximize Attack, you'll need 25 Proteins and something little else. There are many other methods for EV training you can find.
2. IVs
Individual values (also called IVs or individual strengths) are 6 numbers, one for each stat, that every individual Pokémon has. They work as a "talent meter", and are what the judge function tells you is "No Good", "Decent", "Pretty Good", "Very Good", "Great", "Fantastic" or "Best" (in that order!) - an IV can be any number from 0 (no good) to 31 (best). If two Pokémon are the same in everything but an IV in a stat, the one with higher IVs will have that stat higher. Precisely, when scaled to level 100, a Pokemon with IV of 31 in a stat will have 31 points in that stat more than a Pokémon with IV of 0, and a Pokémon with IV 15 will have that stat 15 points higher than the 0 IV one. This is scaled by level just like EVs: at level 50, IVs of 31 mean 15 points more.
An example of IVs? Catch any two Pokémon of the same species at the same level. They will almost certainly have different stats, and that is because of different IVs.
Pokémon hatch with set IVs - you can't change them, except by using Hyper Training, which makes a Pokémon's stats behave like it had IVs of 31. This costs Bottle Caps and can only be done to level 100 Pokémon - so you can make any Pokémon perfectly talented, but it's expensive, so Pokémon bred with high IVs are very wanted by people who want to easily make "perfectly optimized" Pokémon.
Just remember:
IVs are good to have, but EVs are 2 times as important.
3. Natures
Natures affect stats too. Each Nature raises one stat by 10% (indicated by its name being red in the stats screen) and lowers another by 10% (the blue one). If the two stats it raises and lowers are the same, it doesn't change anything. Since Natures can affect any stat except for HP, you have 25 possible Natures. A Nature's effect can be changed by giving the Pokémon a Mint, which are expensive, but much cheaper than Bottle Caps.
4. Which stats to maximize?
There's really no right answer to this. It all depends on the moves you want to teach your Pokémon: when making an "optimal" Pokémon, you first decide on its moves and battle style you want to use with it, and then go maximizing stats that are useful for that.
Let's take your Gyarados as an example.
Imagine you just caught it, never battled with it yet, so that it has 0 EVs in everything. We won't be looking at its IVs at the moment. Imagine you fed it Exp. Candy so that it's at level 100, just so that we can calculate more easily. We want to optimize Gyarados's stats.
First we must decide what we want it optimized
for. Now, we know Gyarados's base stats are
HP: 95
Attack: 125
Defense: 79
Sp. Atk.: 60
Sp. Def.: 100
Speed: 81
This tells us Gyarados in general have very high Attack, high HP and Special Defense, average Defense and Speed and low Special Attack. From this we know that we definitely won't be using Gyarados as a special attacker, but that it will do well as a physical attacker.
So, say we want to use Gyarados offensively and teach it physical moves. This means we will definitely want to optimize its Attack, so we do that, giving Gyarados 63 more points in it.
We'll decide what else to maximize by first deciding on what moves we want. Let's go with simple, straightforward strong physical moves of many types. For example:
- Waterfall, strong Water-type move
- Earthquake, strong Ground-type move that hits Electric-types Gyarados is very weak to
- Bounce, Gyarados's only physical Flying-type move, which is very useful when it's Dynamaxed
- Power Whip, strong Grass-type move, good against other Water-types
You can now go two ways: you may want Gyarados to be fast, take opponents down before they can hurt it. In that case you maximize Speed, making it 63 points higher.
On the other hand, Gyarados is quite bulky and can take a hit. You may think being very durable is more useful than being faster, in which case you maximize its HP, giving it 63 more hit points. In that case you can still make it very fast in battle by Dynamaxing and using Max Airstream (a very popular strategy for Gyarados).
The choice is yours. You can think of a totally different way to use Gyarados from those I stated, and for it something else would be useful to optimize.
If you want a Pokémon with perfect IVs and Nature for what you need, you can either find or breed one with high IVs and a helpful nature, or you can feed one you have Mints and Hyper Train it to get that.
Hope this helped!