Ideal Gas Law Calculator
Calculate pressure, volume, temperature, or moles using PV=nRT. Includes P-V and T-V diagrams and standard conditions reference.
The Ideal Gas Law, expressed mathematically as PV=nRT, is the fundamental equation of state in thermodynamics and physical chemistry that describes the behavior of a hypothetical "ideal" gas under various conditions. By linking pressure, volume, temperature, and the number of molecules into a single cohesive formula, this principle allows scientists and engineers to predict exactly how a gas will respond when its environment changes. Whether you are a chemist synthesizing compounds in a laboratory, an aerospace engineer designing pressurized spacecraft cabins, or a student encountering thermodynamics for the first time, mastering this law is the gateway to understanding the physical mechanics of the gaseous world.
What It Is and Why It Matters
The Ideal Gas Law is a mathematical equation that relates the four primary state variables of a gas: pressure, volume, temperature, and the amount of the gas measured in moles. In the physical sciences, an "equation of state" is a mathematical model that describes the state of matter under a given set of physical conditions. The Ideal Gas Law is the most famous and widely used equation of state because it provides a remarkably accurate approximation of how real gases behave under standard, everyday conditions. It posits a hypothetical substance—an "ideal gas"—whose particles occupy no volume of their own and exert no attractive or repulsive forces upon one another. While no perfectly ideal gas exists in reality, gases like helium, nitrogen, and oxygen at room temperature and atmospheric pressure behave so similarly to this mathematical ideal that the equation is practically flawless for everyday calculations.
Understanding this law matters because gases are uniquely compressible and expansive compared to solids and liquids. If you heat a block of solid iron, its volume changes by a microscopic, almost negligible fraction. However, if you heat a trapped volume of gas, it will expand dramatically, or, if confined to a rigid container, its pressure will skyrocket. The Ideal Gas Law solves the critical problem of predictability. Without it, engineers could not safely design pressurized scuba tanks, meteorologists could not calculate atmospheric density to predict weather patterns, and automotive engineers could not properly calibrate the explosive expansion of gases required to deploy a car’s airbag in milliseconds. It provides a deterministic, reliable framework for calculating exactly what will happen to a gas when you manipulate its environment, making it an indispensable tool across virtually every hard science and engineering discipline.
History and Origin
The Ideal Gas Law was not discovered in a single "eureka" moment by one individual, but rather pieced together over nearly two centuries of meticulous experimental observation. The story begins in 1662 with the Anglo-Irish chemist Robert Boyle. By trapping air in a J-shaped glass tube using liquid mercury, Boyle observed that the pressure and volume of a gas are inversely proportional; if you double the pressure on a gas, its volume shrinks by exactly half, provided the temperature remains constant. This became known as Boyle's Law. More than a century later, in 1787, the French physicist and ballooning pioneer Jacques Charles discovered that the volume of a gas is directly proportional to its absolute temperature. Charles noted that as he heated gases, they expanded predictably, laying the groundwork for Charles's Law, which was formally published by Joseph Louis Gay-Lussac in 1802.
The next major puzzle piece arrived in 1811, when the Italian scientist Amedeo Avogadro proposed a radical hypothesis: equal volumes of all gases, at the same temperature and pressure, contain the exact same number of molecules. Avogadro's Law meant that the sheer number of gas particles (the moles) directly dictated the volume they occupied, regardless of whether the gas was lightweight hydrogen or heavy carbon dioxide. Finally, in 1834, the French engineer and physicist Émile Clapeyron achieved a monumental synthesis. Clapeyron recognized that Boyle's, Charles's, and Avogadro's empirical observations were merely different facets of the same underlying physical truth. He combined these individual proportions into a single, unified equation of state: PV = R(267+t), which was the first iteration of the Ideal Gas Law. Later, when Lord Kelvin established the absolute temperature scale in 1848, the equation was refined into the elegant, modern PV=nRT format we use today. This historical evolution represents one of the greatest triumphs of the scientific method, transitioning from isolated physical observations to a universal mathematical law.
Key Concepts and Terminology
To utilize the Ideal Gas Law effectively, you must possess a crystal-clear understanding of the five variables that make up the equation: PV=nRT. Each variable represents a specific physical property, and mixing up their definitions or units is the primary source of error for beginners.
Pressure (P)
Pressure is the force exerted by gas molecules as they continuously collide with the walls of their container. Imagine millions of microscopic billiard balls bouncing around inside a box; every time a ball strikes a wall, it pushes against it. The sum of all these microscopic impacts over a specific area constitutes pressure. In the Ideal Gas Law, pressure is typically measured in atmospheres (atm), where 1 atm represents the standard pressure of Earth's atmosphere at sea level. Other common units include Pascals (Pa), kilopascals (kPa), millimeters of mercury (mmHg), and torr.
Volume (V)
Volume is the three-dimensional space that the gas occupies. Because gases expand to fill their containers completely, the volume of the gas is always exactly equal to the internal volume of the container holding it. In standard chemistry calculations using the Ideal Gas Law, volume is almost universally measured in liters (L). If you are given a volume in milliliters (mL) or cubic centimeters ($cm^3$), you must convert it to liters by dividing by 1,000 before plugging it into the equation.
Moles (n)
The variable 'n' represents the amount of substance, measured in moles. The mole is a fundamental unit in chemistry that bridges the gap between the microscopic world of atoms and the macroscopic world we can measure. One mole of any substance contains exactly $6.022 \times 10^{23}$ particles (Avogadro's number). Therefore, 'n' does not measure the weight or mass of the gas in grams; it measures the sheer headcount of molecules bouncing around inside the container. To find 'n', you typically divide the mass of your gas in grams by its molar mass (grams per mole).
Temperature (T)
Temperature is a measure of the average kinetic energy of the gas molecules. The hotter the gas, the faster its molecules are moving, and the more violently they strike the container walls. For the Ideal Gas Law to function mathematically, temperature must always be measured on an absolute scale, specifically the Kelvin (K) scale. Absolute zero (0 K) represents the theoretical point where all molecular motion stops. You can never use Celsius or Fahrenheit in this equation, because those scales include negative numbers and zero points that do not correspond to zero kinetic energy, which would mathematically break the formula.
The Universal Gas Constant (R)
The variable 'R' is the proportionality constant that makes the entire equation work. It bridges the units of pressure, volume, temperature, and moles so they equate perfectly on both sides of the equal sign. The numerical value of R changes depending entirely on the units you choose for pressure and volume. If you are measuring pressure in atmospheres (atm) and volume in liters (L), R is exactly $0.08206 \text{ L}\cdot\text{atm}/(\text{mol}\cdot\text{K})$. If you are measuring pressure in kilopascals (kPa) and volume in liters, R becomes $8.314 \text{ J}/(\text{mol}\cdot\text{K})$. Selecting the correct value for R is the crucial linchpin of any ideal gas calculation.
How It Works — Step by Step
The mathematical mechanics of the Ideal Gas Law rely on basic algebra. The master equation is $PV = nRT$. Because there are four distinct variables (P, V, n, T) and one constant (R), you can solve for any single variable as long as you know the other three. You simply use algebraic division to isolate the unknown variable on one side of the equal sign. If you need to find Pressure, you divide both sides by Volume, resulting in $P = (nRT) / V$. If you need to find Volume, the formula becomes $V = (nRT) / P$. To find the number of moles, you isolate 'n' to get $n = (PV) / (RT)$. Finally, to find the Temperature, you rearrange the formula to $T = (PV) / (nR)$.
Full Worked Example: Calculating Pressure
Let us walk through a highly realistic scenario. Imagine you are a chemical engineer filling a rigid steel tank with nitrogen gas ($N_2$). The tank has an internal volume of 50.0 liters. You pump exactly 120.0 grams of nitrogen gas into the tank. The ambient temperature in the laboratory is 22.0 degrees Celsius. You need to calculate the exact internal pressure of the tank in atmospheres to ensure it does not exceed the steel's safety rating.
Step 1: Convert all variables to the correct standard units.
- Volume (V): The volume is already in liters (50.0 L), so no conversion is needed.
- Temperature (T): The temperature is in Celsius. You must convert to Kelvin by adding 273.15. $22.0 + 273.15 = 295.15 \text{ K}$.
- Moles (n): You have 120.0 grams of $N_2$, but the formula requires moles. The molar mass of a single nitrogen atom is 14.01 g/mol. Because nitrogen gas is diatomic ($N_2$), its molar mass is $14.01 \times 2 = 28.02 \text{ g/mol}$. To find moles, divide the mass by the molar mass: $120.0 \text{ g} / 28.02 \text{ g/mol} = 4.283 \text{ moles}$.
- Gas Constant (R): Because we want our final pressure in atmospheres, and our volume is in liters, we must use the specific R value that matches those units: $0.08206 \text{ L}\cdot\text{atm}/(\text{mol}\cdot\text{K})$.
Step 2: Set up the rearranged equation. We are solving for Pressure (P), so we use the rearranged formula: $P = (nRT) / V$.
Step 3: Plug in the numbers and calculate. $P = (4.283 \text{ moles} \times 0.08206 \text{ L}\cdot\text{atm}/(\text{mol}\cdot\text{K}) \times 295.15 \text{ K}) / 50.0 \text{ L}$ $P = (103.737 \text{ L}\cdot\text{atm}) / 50.0 \text{ L}$ $P = 2.075 \text{ atm}$
The final pressure inside the steel tank is 2.075 atmospheres. By meticulously converting the units and following the algebraic steps, we have derived a highly accurate physical measurement using only theoretical math. A reader following along with a pencil and paper should replicate these exact steps—convert units, choose R, rearrange the formula, and solve—for every single gas law problem they encounter.
Types, Variations, and Methods
While $PV=nRT$ is the ultimate master equation, it is actually the culmination of several simpler, highly useful constituent laws. These variations are incredibly practical when you are dealing with a sealed container where the amount of gas (moles) does not change, but the environmental conditions do. Instead of using the full Ideal Gas Law twice, you can use these specialized variations to compare a "Before" state to an "After" state.
Boyle's Law ($P_1V_1 = P_2V_2$)
Boyle's Law is used when temperature and the number of moles remain strictly constant. It states that pressure and volume are inversely proportional. If you squeeze a gas into a smaller space, the pressure goes up. For example, if you have a 10.0 L syringe filled with air at 1.0 atm of pressure ($V_1$ and $P_1$), and you push the plunger down until the volume is only 5.0 L ($V_2$), the new pressure ($P_2$) will exactly double to 2.0 atm. This variation is heavily used in pneumatics and respiratory physiology.
Charles's Law ($V_1/T_1 = V_2/T_2$)
Charles's Law applies when pressure and moles are held constant. It dictates that volume and absolute temperature are directly proportional. If you heat a gas, it expands. Consider a perfectly elastic balloon holding 2.0 L of helium at 300 K. If you place that balloon in a hot car and its temperature rises to 330 K (a 10% increase), the volume of the balloon will also increase by 10%, swelling to 2.2 L. This law is the foundational principle behind hot air ballooning.
Gay-Lussac's Law ($P_1/T_1 = P_2/T_2$)
Gay-Lussac's Law is utilized when volume and moles are constant, such as in a rigid, sealed metal canister. It states that pressure and absolute temperature are directly proportional. If you throw a sealed aerosol can into a campfire, the volume of the can cannot change. As the temperature of the trapped gas skyrockets, the pressure skyrockets proportionally until the metal yields and the can explodes. This variation is critical for designing pressurized safety valves in industrial boilers.
The Combined Gas Law ($(P_1V_1)/T_1 = (P_2V_2)/T_2$)
When pressure, volume, and temperature are all changing simultaneously, but the actual mass of the gas remains sealed inside the container, professionals use the Combined Gas Law. This eliminates the need to calculate the exact number of moles or use the gas constant R. You simply plug in the initial pressure, volume, and temperature on the left side, and solve for whichever variable is missing in the final state on the right side. It is the most efficient method for analyzing sealed-system thermodynamic cycles, such as the compression and combustion strokes inside an internal combustion engine.
Real-World Examples and Applications
The abstract mathematics of the Ideal Gas Law translate into tangible, life-saving, and industry-defining applications across the modern world. To understand its power, we must look at concrete scenarios where professionals rely on these calculations to make critical decisions.
Consider a 32-year-old commercial scuba diver preparing for a deep-water pipeline inspection. The diver uses a standard aluminum scuba cylinder with an internal volume of exactly 11.1 liters. The dive shop fills this tank with compressed air to a gauge pressure of 200 atmospheres at an ambient room temperature of 298 K (25°C). The diver's life depends on knowing exactly how much air is in that tank. Using the Ideal Gas Law ($n = PV/RT$), the diver can calculate the exact molar quantity of air. Multiplying 200 atm by 11.1 L yields 2220. Dividing that by the product of R (0.08206) and T (298 K), which is 24.45, reveals that the tank holds exactly 90.8 moles of breathable air. If the diver knows their body consumes approximately 1.5 moles of air per minute at a specific depth, they can definitively calculate that they have exactly 60.5 minutes of bottom time before the tank runs entirely dry.
Another profound application is found in automotive safety engineering, specifically in the deployment of airbags. When a car registers a collision, a sensor triggers the ignition of a solid chemical pellet, usually sodium azide ($NaN_3$). This solid rapidly decomposes into solid sodium and raw nitrogen gas ($N_2$). Engineers must calculate exactly how many grams of sodium azide to place in the steering wheel. If the airbag requires a volume of 60.0 liters to fully inflate, and must reach a pressure of 1.2 atmospheres to properly cushion a human head at an estimated deployment temperature of 300 K, the engineer uses $n = PV/RT$ to find the required moles of nitrogen gas. Plugging in the numbers ($1.2 \times 60.0 / (0.08206 \times 300)$) dictates that exactly 2.92 moles of nitrogen gas are required. Using stoichiometry, the engineer translates those 2.92 moles of gas into the precise fractional gram weight of solid sodium azide needed on the assembly line. A millimeter's difference in the pellet size, calculated via the Ideal Gas Law, is the difference between life and death in a 70 mph collision.
Common Mistakes and Misconceptions
Despite its mathematical simplicity, the Ideal Gas Law is a minefield for beginners. The errors rarely stem from an inability to perform basic algebra; rather, they arise from fundamental misunderstandings of the physical properties the variables represent.
The single most ubiquitous mistake—one that plagues high school chemistry students and novice engineers alike—is failing to convert temperatures to the Kelvin scale. It is incredibly common to see a student plug 25°C directly into the equation. Because 25 is a relatively small number compared to 298.15 (its Kelvin equivalent), this mistake results in an answer that is catastrophically wrong, often off by an order of magnitude. Furthermore, if a problem involves a temperature of 0°C, plugging a zero into the denominator of a rearranged equation causes a "divide by zero" mathematical error, completely breaking the calculation. Always, without exception, add 273.15 to your Celsius temperature before doing anything else.
Another pervasive misconception is the belief that 'n' represents the mass of the gas in grams. If a problem states "50 grams of oxygen gas," a beginner will frequently plug the number 50 directly into the 'n' variable. The equation does not care how heavy the gas is; it only cares how many individual particles are striking the container walls. 50 grams of lightweight helium will exert a massively higher pressure than 50 grams of heavy radon gas, because 50 grams of helium contains drastically more individual atoms. You must always divide the given gram mass by the specific molar mass of the chemical in question to find the true mole count before proceeding.
Finally, professionals often see beginners mismatching the units of Pressure, Volume, and the Gas Constant (R). If your pressure is measured in kilopascals (kPa), but you use the R value intended for atmospheres (0.08206), your final answer will be completely nonsensical. The units of your variables must perfectly match the units embedded within your chosen R constant. If they do not match, you must either convert your pressure and volume to match R, or select a different R value that matches your pressure and volume.
Best Practices and Expert Strategies
Experienced chemists and thermodynamic engineers do not simply plug numbers into a calculator and hope for the best; they employ rigid cognitive frameworks and best practices to guarantee accuracy and catch potential errors before they compound.
The most critical expert strategy is the rigorous use of dimensional analysis, also known as the factor-label method. When an expert writes out an Ideal Gas Law calculation, they do not just write the numbers; they write the units attached to every single number, and they manually cross out the units that cancel each other out during the calculation. For example, when calculating volume ($V = nRT/P$), an expert writes: $V = (\text{moles} \times (\text{L}\cdot\text{atm}/(\text{mol}\cdot\text{K})) \times \text{K}) / \text{atm}$. By visually crossing out 'moles' in the numerator and denominator, crossing out 'K', and crossing out 'atm', the only unit left standing on the paper is 'L' (Liters). If an expert finishes crossing out units and is left with something bizarre—like an answer for Volume measured in "atmospheres per degree"—they instantly know they set up the algebra incorrectly or chose the wrong R constant, allowing them to fix the error before finalizing the report.
Another hallmark of expert practice is the "Sanity Check" via proportional reasoning. Before touching a calculator, a professional will look at the initial and final states of a system and estimate the direction of the change. If they are calculating the new volume of a gas after the pressure has been tripled and the temperature has been cut in half, they know via Boyle's and Charles's laws that the volume must dramatically decrease. If their final calculated answer shows a volume larger than the starting volume, they immediately know a mathematical error occurred, likely a flipped numerator and denominator. Experts build an intuitive mental model of how gases behave, using the math only to pinpoint the exact decimal value of a change they have already broadly predicted.
Edge Cases, Limitations, and Pitfalls
The most dangerous pitfall of the Ideal Gas Law is forgetting the word "Ideal." The equation is built on two massive assumptions: first, that gas molecules are infinitely small point-masses that take up exactly zero physical volume; and second, that gas molecules exert absolutely zero electromagnetic attractive or repulsive forces on one another when they fly past each other. Under normal room temperatures and standard atmospheric pressures, these assumptions are "close enough" to reality that the errors are negligible (usually less than a 1% deviation). However, when you push gases to extreme physical limits, the Ideal Gas Law breaks down spectacularly.
The first major limitation occurs at extremely high pressures. Imagine compressing a gas from 1 atmosphere to 500 atmospheres inside an industrial compressor. At 1 atm, the empty space between the molecules is so vast that the physical size of the molecules themselves doesn't matter. But at 500 atm, the molecules are crammed so tightly together that the actual physical volume of the atoms begins to take up a significant percentage of the container's total space. The Ideal Gas Law assumes the gas can be compressed infinitely, but real gases have a hard physical limit. If you use $PV=nRT$ to calculate the volume of a gas at 500 atm, your calculated volume will be noticeably smaller than the actual, real-world volume, because the math ignores the physical bulk of the atoms.
The second major limitation occurs at extremely low temperatures, right before a gas condenses into a liquid. As temperature drops, gas molecules slow down. When they move sluggishly past one another, the weak intermolecular attractive forces (like Van der Waals dispersion forces or dipole-dipole interactions) have time to grab hold. The molecules begin to stick together slightly, pulling inward. This inward pull reduces the force with which they strike the container walls. Consequently, if you use the Ideal Gas Law to calculate the pressure of a freezing gas just above its condensation point, the equation will predict a pressure significantly higher than the true measured pressure, because the math assumes the molecules are completely ignoring each other.
To quantify these deviations, engineers use the Compressibility Factor (Z). For a perfectly ideal gas, $Z = 1$ exactly. If a real gas under specific conditions has a Z factor of 0.8 or 1.2, it means the gas is deviating from ideal behavior by 20%, and the standard PV=nRT equation should not be trusted for high-precision engineering tasks.
Comparisons with Alternatives
Because the Ideal Gas Law fails under extreme conditions, physical chemists and engineers have developed alternative, more complex equations of state to model "real" gases. Choosing between the Ideal Gas Law and these alternatives is a constant exercise in balancing mathematical simplicity against required precision.
The Van der Waals Equation
The most famous alternative is the Van der Waals equation, formulated in 1873. The formula is: $(P + a(n/V)^2)(V - nb) = nRT$. Notice that it looks exactly like $PV=nRT$, but with two correction factors added to the Pressure and Volume terms. The 'a' parameter corrects for the intermolecular attractive forces (adjusting the pressure), while the 'b' parameter corrects for the physical volume taken up by the gas molecules themselves (adjusting the available volume). Every single chemical element and compound has its own unique, experimentally determined 'a' and 'b' values. The Van der Waals equation is vastly more accurate than the Ideal Gas Law at high pressures and low temperatures. However, the trade-off is computational complexity. Solving for Volume (V) in the Van der Waals equation results in a cubic polynomial, which is notoriously difficult to solve algebraically without numerical approximation software.
Redlich-Kwong and Peng-Robinson Equations
In modern chemical engineering, particularly in the petrochemical industry where calculating the behavior of highly pressurized hydrocarbon gases is a daily requirement, professionals rely on even more advanced models like the Redlich-Kwong equation or the Peng-Robinson equation. These models introduce temperature-dependent correction factors and complex thermodynamic parameters that predict gas behavior with astonishing accuracy, even right at the critical point where gases transition into liquids.
When to choose which? If you are a student, a scuba diver, or a laboratory technician working at near-room temperatures and pressures under 10 atmospheres, the Ideal Gas Law is universally preferred. It is fast, requires no lookup tables for specific chemical parameters, and is accurate enough for 99% of daily tasks. If you are an engineer designing a cryogenic liquid nitrogen storage facility, or modeling the injection of pressurized methane into a deep-sea oil well at 400 atmospheres, the Ideal Gas Law is dangerously inadequate. In those high-stakes, extreme-environment scenarios, the computational burden of Peng-Robinson or Van der Waals is a mandatory cost of doing business safely.
Industry Standards and Benchmarks
To ensure scientists and engineers around the globe are speaking the exact same language when discussing gas volumes and pressures, international regulatory bodies have established strict benchmark conditions. When you read a scientific paper that says "15 liters of oxygen gas," that volume is meaningless unless you know the temperature and pressure it was measured at. To solve this, the industry relies on standard reference states.
Standard Temperature and Pressure (STP)
The most common benchmark is STP, defined by the International Union of Pure and Applied Chemistry (IUPAC). Historically, STP was defined as a temperature of exactly 273.15 K (0°C) and a pressure of exactly 1 atmosphere (101.325 kPa). Under these historical STP conditions, one mole of any ideal gas occupies a highly specific benchmark volume: exactly 22.414 Liters. This is known as the standard molar volume. If a high school chemistry problem asks for the volume of 2 moles of hydrogen gas at STP, you do not even need to use the full PV=nRT equation; you simply multiply 2 moles by 22.4 L/mol to get 44.8 Liters.
Note on Modern Standards: In 1982, IUPAC slightly updated the definition of STP pressure from 1 atm to exactly 100 kPa (1 bar). Under this new, strictly metric standard, the standard molar volume shifted slightly to 22.711 Liters. While professional scientific literature strictly adheres to the 100 kPa / 22.7 L standard, many legacy textbooks and educational curricula still teach the 1 atm / 22.4 L standard. An expert practitioner must always verify which version of STP a client or textbook is utilizing.
Standard Ambient Temperature and Pressure (SATP)
Because 0°C is a freezing temperature that does not reflect normal laboratory working conditions, another common benchmark is SATP. This standard is defined as a temperature of 298.15 K (25°C, standard room temperature) and a pressure of exactly 1 bar (100 kPa). Under SATP conditions, the molecules are hotter and moving faster, causing the gas to expand. Therefore, the standard molar volume of an ideal gas at SATP is 24.789 Liters. When chemical engineers calculate the yield of a gas-producing reaction occurring on an open laboratory benchtop, they default to SATP benchmarks rather than STP.
Frequently Asked Questions
What happens if I use Fahrenheit or Celsius instead of Kelvin? If you use Fahrenheit or Celsius, your calculation will be entirely incorrect, often resulting in negative pressures or volumes, which are physically impossible. The Ideal Gas Law relies on proportional multiplication and division. Because 0°C and 0°F do not represent zero kinetic energy, scaling these temperatures mathematically breaks the proportions. Kelvin is an absolute scale where 0 K means zero molecular motion, making it the only mathematically valid temperature scale for thermodynamic equations.
Why are there so many different values for the Gas Constant (R)? The physical constant 'R' represents the exact same amount of fundamental thermodynamic energy in every version, but it is expressed in different "languages" (units). Just as 1 inch and 2.54 centimeters represent the exact same physical distance, $0.08206 \text{ L}\cdot\text{atm}/(\text{mol}\cdot\text{K})$ and $8.314 \text{ J}/(\text{mol}\cdot\text{K})$ represent the exact same proportionality. You choose the R value that contains the specific units of pressure and volume you are currently working with, allowing those units to cancel out properly during the algebra.
Can I use the Ideal Gas Law for liquids or solids? Absolutely not. The Ideal Gas Law is explicitly an equation of state for gases. Liquids and solids are relatively incompressible because their molecules are already in direct physical contact with one another. Their volumes do not change significantly with pressure, and their behavior is governed by entirely different, much more complex physical laws regarding fluid dynamics and crystalline structures. Applying PV=nRT to liquid water will yield wildly incorrect and useless results.
Does the Ideal Gas Law work for gas mixtures, like air? Yes, it works exceptionally well for gas mixtures, thanks to Dalton's Law of Partial Pressures. Because the Ideal Gas Law assumes gas molecules do not interact with one another, the identity of the gas does not matter. If you have a container with 1 mole of oxygen and 3 moles of nitrogen, you simply treat it as 4 total moles of "gas." You plug $n = 4$ into the equation, and the resulting pressure calculation will perfectly represent the total combined pressure of the atmospheric mixture.
How do I handle a problem where the gas is collected "over water"? When a gas is collected over liquid water in a laboratory experiment, the trapped gas is not pure; it is a mixture of the target gas and evaporated water vapor. To use the Ideal Gas Law to find the amount of your target gas, you must first subtract the "vapor pressure of water" (which depends on the room's temperature and can be found in reference tables) from the total measured pressure of the container. Once you subtract the water's pressure, you plug the remaining pressure into PV=nRT to solve for the moles of your specific dry gas.
What is the difference between an Ideal Gas and a Real Gas? An ideal gas is a mathematical fiction where molecules are treated as infinitely small dots that never attract or repel each other. A real gas consists of actual physical atoms that take up microscopic amounts of space and exert weak electromagnetic pulls on one another. Under normal, everyday conditions, real gases behave so similarly to the mathematical fiction that the difference is negligible. However, under extreme cold or extreme pressure, real gases deviate from the math, requiring more complex formulas like the Van der Waals equation to model accurately.