How did planes like the I-15 ( Spanish Civil war - Early ww2) have 3000 rounds of ammunition to then planes like the Yak-9 ( around 1942 maiden flight) only having around 300. Thanks for replies if there are any.
Largely the size of the ammunition. The I-15 used PV-1 machine guns, an air-cooled variant of the 1910 Maxim gun. These fired 7.62x54mmR ammunition, with an overall length of 3.038in and a diameter of 0.570in. this allowed 750 rounds per gun in a 4 gun configuration.
In contrast, the Yak-9 had many different armaments over it's service life, such as the 45mm NS-45 cannon, which couldn't fired under 220mph because it would stall out the aircraft, the NS-37, with similar problems and 30 rounds of ammunition, the NS-23 23mm autocannon, with 60 rounds, VYa 23mm autocannons, and 20mm autocannons such as the B-20, ShVAK, and secondary .50 (12.7mm) caliber machine guns that could also be swapped out for 20mms in certain configurations.
Past the increasing size of the ammunition physically limiting the quantity a plane could carry, increasing the caliber at the cost of ammunition capacity was a common practice across the world at that time, as planes were getting bigger, faster, and more heavily armoured. Where before a biplane could keep its nose on target for several seconds to fire its smaller caliber machine guns for longer, as planes got faster the window to fire got smaller and larger guns were needed to deliver the same damage in a shorter amount of time. You can see this trend in every country heavily involved in world war 2, with France, Britain, and France opting for the Hispano-Suiza HS.404 in place of their earlier machine guns, for example on the British spitfire and hurricane, with the latter eventually requiring twelve .303 caliber machine guns to effectively combat German bombers. Starting in 1941 they replaced these with four of the aforementioned HS.404 (Hispano Mk.II) which achieved the same effectiveness despite having thousands of rounds fewer ammunition. The heavier armament allowed them to disable German bombers at higher speeds and fewer bullets, which meant less time in range of the German tail gunners. This was seen as a distinct advantage despite the massively decreased ammunition load from earlier versions.
In later German aircraft, this philosophy is even more obvious, with their attention focused on intercepting American and British bombers, they also uparmed their aircraft at the cost of ammunition capacity. Going from 7.92mm machine guns early on, to 20mm autocannon, and increasing the caliber even further to 30mm autocannons for disabling bombers in as few hits as possible, sacrificing almost every other aspect of the design such as weight, velocity, cost, and indeed ammo capacity to achieve higher damage on target.
Of course these examples are all interceptor aircraft designed to operate over friendly territory and shoot down aggressor aircraft, which meant a short range and small ammo load to maximize performance. For long range escort aircraft such as the P-51 Mustang, it retained its .50 caliber machine guns throughout the war because they were used for endurance missions over enemy territory where they had nowhere to land and rearm should they run out. Along with their combatants being German fighters, not bombers, they didn't need as heavy armament because the tradeoffs didn't make sense in this application. They needed to be light with endurance in mind rather than short range interception.
Going back to your question, the Yak-9 was a quick development for the soviet union, as they didn't have decades of advanced further planes to build experience off of. Because of that their wings were not capable of being strong enough while also holding fuel, undercarriage, and weapons, so the guns had to be fitted in the nose with interrupter gear behind the propeller. With larger and larger engines, the space for ammunition belts decreased accordingly and the soviets prioritized large engines that could reach high top speeds to evade enemy gunfire over endurance ammunition loads since their airfields were generally much closer to the action than the other allies. Being the primary fighter of the Soviet union had such a large variety of armament options that it could be outfitted with almost any combination for the role it was intended, including anti-shipping with the 45mm and 37mm cannons.