{"id":2523,"date":"2026-02-18T20:39:28","date_gmt":"2026-02-18T18:39:28","guid":{"rendered":"https:\/\/science-x.net\/?page_id=2523"},"modified":"2026-02-18T20:41:34","modified_gmt":"2026-02-18T18:41:34","slug":"ideal-gas-law-calculator-pv-nrt","status":"publish","type":"page","link":"https:\/\/science-x.net\/?page_id=2523","title":{"rendered":"Ideal Gas Law Calculator (pV = nRT)"},"content":{"rendered":"\n<div class=\"eco-tool wp-block-group\" id=\"eco-tool-ideal-gas\">\n  <div class=\"eco-tool__header\">\n    <h2 class=\"eco-tool__title\">Ideal Gas Law Calculator (pV = nRT)<\/h2>\n    <p class=\"eco-tool__lead\">\n      Solve for pressure, volume, moles, or temperature using the ideal gas equation. Optional: estimate gas mass from molar mass.\n    <\/p>\n  <\/div>\n\n  <form class=\"eco-tool__form\" novalidate>\n    <div class=\"eco-tool__grid3\">\n      <!-- Unknown -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Solve for (unknown)<\/label>\n        <select class=\"eco-tool__input\" data-gas=\"unknown\">\n          <option value=\"p\" selected>Pressure (P)<\/option>\n          <option value=\"v\">Volume (V)<\/option>\n          <option value=\"n\">Moles (n)<\/option>\n          <option value=\"t\">Temperature (T)<\/option>\n        <\/select>\n        <div class=\"eco-tool__hint\">Fill the other three values.<\/div>\n      <\/div>\n\n      <!-- Pressure -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Pressure (P)<\/label>\n        <div class=\"eco-tool__row\">\n          <input class=\"eco-tool__input\" data-gas=\"p\" type=\"number\" step=\"any\" placeholder=\"e.g., 101.325\" inputmode=\"decimal\" \/>\n          <select class=\"eco-tool__input eco-tool__unit\" data-gas=\"pUnit\">\n            <option value=\"pa\">Pa<\/option>\n            <option value=\"kpa\" selected>kPa<\/option>\n            <option value=\"bar\">bar<\/option>\n            <option value=\"atm\">atm<\/option>\n          <\/select>\n        <\/div>\n        <div class=\"eco-tool__hint\">Choose units for P.<\/div>\n      <\/div>\n\n      <!-- Volume -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Volume (V)<\/label>\n        <div class=\"eco-tool__row\">\n          <input class=\"eco-tool__input\" data-gas=\"v\" type=\"number\" step=\"any\" placeholder=\"e.g., 24.0\" inputmode=\"decimal\" \/>\n          <select class=\"eco-tool__input eco-tool__unit\" data-gas=\"vUnit\">\n            <option value=\"m3\">m\u00b3<\/option>\n            <option value=\"l\" selected>L<\/option>\n          <\/select>\n        <\/div>\n        <div class=\"eco-tool__hint\">Choose units for V.<\/div>\n      <\/div>\n\n      <!-- Moles -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Amount (n) (moles)<\/label>\n        <input class=\"eco-tool__input\" data-gas=\"n\" type=\"number\" step=\"any\" placeholder=\"e.g., 1\" inputmode=\"decimal\" \/>\n        <div class=\"eco-tool__hint\">Number of moles.<\/div>\n      <\/div>\n\n      <!-- Temperature -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Temperature (T)<\/label>\n        <div class=\"eco-tool__row\">\n          <input class=\"eco-tool__input\" data-gas=\"t\" type=\"number\" step=\"any\" placeholder=\"e.g., 25\" inputmode=\"decimal\" \/>\n          <select class=\"eco-tool__input eco-tool__unit\" data-gas=\"tUnit\">\n            <option value=\"k\">K<\/option>\n            <option value=\"c\" selected>\u00b0C<\/option>\n          <\/select>\n        <\/div>\n        <div class=\"eco-tool__hint\">\u00b0C will be converted to Kelvin.<\/div>\n      <\/div>\n\n      <!-- Molar mass (optional) -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Molar mass (optional) (g\/mol)<\/label>\n        <input class=\"eco-tool__input\" data-gas=\"mm\" type=\"number\" min=\"0\" step=\"any\" placeholder=\"e.g., 28.97\" inputmode=\"decimal\" \/>\n        <div class=\"eco-tool__hint\">If provided, mass = n \u00d7 molar mass.<\/div>\n      <\/div>\n\n      <!-- Formulas -->\n      <div class=\"eco-tool__field\">\n        <label class=\"eco-tool__label\">Formulas<\/label>\n        <div class=\"eco-tool__noteBox\">\n          pV = nRT<br>\n          R = 8.314462618 J\/(mol\u00b7K)<br>\n          mass (g) = n \u00b7 (g\/mol)\n        <\/div>\n        <div class=\"eco-tool__hint\">Assumes ideal gas behavior.<\/div>\n      <\/div>\n    <\/div>\n\n    <div class=\"eco-tool__actions\">\n      <button type=\"button\" class=\"wp-element-button eco-tool__btn\" data-gas=\"calc\">Calculate<\/button>\n      <button type=\"button\" class=\"wp-element-button eco-tool__btn eco-tool__btn--ghost\" data-gas=\"reset\">Reset<\/button>\n      <div class=\"eco-tool__error\" data-gas=\"error\" aria-live=\"polite\"><\/div>\n    <\/div>\n  <\/form>\n\n  <div class=\"eco-tool__result\" data-gas=\"result\" hidden>\n    <h3 class=\"eco-tool__subtitle\">Results<\/h3>\n\n    <div class=\"eco-tool__cards\">\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Pressure (P)<\/div>\n        <div class=\"eco-tool__metric-value\" data-gas=\"outP\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub\">Pa<\/div>\n      <\/div>\n\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Volume (V)<\/div>\n        <div class=\"eco-tool__metric-value\" data-gas=\"outV\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub\">m\u00b3<\/div>\n      <\/div>\n\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Moles (n)<\/div>\n        <div class=\"eco-tool__metric-value\" data-gas=\"outN\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub\">mol<\/div>\n      <\/div>\n\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Temperature (T)<\/div>\n        <div class=\"eco-tool__metric-value\" data-gas=\"outT\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub\">K<\/div>\n      <\/div>\n    <\/div>\n\n    <div class=\"eco-tool__cards\" style=\"margin-top:10px;\">\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Estimated mass (optional)<\/div>\n        <div class=\"eco-tool__metric-value\" data-gas=\"outMass\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub\">grams<\/div>\n      <\/div>\n\n      <div class=\"eco-tool__card\">\n        <div class=\"eco-tool__metric-label\">Equation used<\/div>\n        <div class=\"eco-tool__metric-sub\" data-gas=\"eq\">\u2014<\/div>\n        <div class=\"eco-tool__metric-sub eco-tool__muted\">All calculations are done in SI.<\/div>\n      <\/div>\n    <\/div>\n\n    <p class=\"eco-tool__note\">\n      At high pressures\/low temperatures, real gases deviate from ideal behavior.\n    <\/p>\n  <\/div>\n<\/div>\n\n<style>\n.eco-tool{border:1px solid rgba(0,0,0,.12);border-radius:12px;padding:16px}\n.eco-tool__grid3{display:grid;grid-template-columns:1fr;gap:16px}\n@media (min-width:860px){.eco-tool__grid3{grid-template-columns:1fr 1fr 1fr}}\n.eco-tool__field{display:flex;flex-direction:column;gap:6px}\n.eco-tool__label{font-weight:600}\n.eco-tool__input{height:44px;padding:0 8px;border:1px solid rgba(0,0,0,.2);border-radius:10px;background:#fff;font:inherit;box-sizing:border-box}\n.eco-tool__hint{font-size:.92em;opacity:.78;min-height:34px}\n.eco-tool__noteBox{border:1px solid rgba(0,0,0,.12);border-radius:12px;padding:12px;background:rgba(0,0,0,.02)}\n.eco-tool__row{display:flex;gap:10px}\n.eco-tool__unit{max-width:120px}\n\n.eco-tool__actions{display:flex;gap:10px;margin-top:16px;align-items:center;flex-wrap:wrap}\n.eco-tool__btn{padding:10px 22px}\n.eco-tool__btn--ghost{background:transparent!important;border:1px solid rgba(0,0,0,.2)!important}\n.eco-tool__btn--ghost:hover,.eco-tool__btn--ghost:focus{background:rgba(0,0,0,.06)!important;border-color:rgba(0,0,0,.35)!important}\n.eco-tool__error{font-weight:600;min-height:1.2em;flex:1 1 240px}\n\n.eco-tool__result{margin-top:16px}\n.eco-tool__subtitle{margin:0 0 10px}\n.eco-tool__cards{display:grid;gap:10px;grid-template-columns:1fr}\n@media (min-width:860px){.eco-tool__cards{grid-template-columns:1fr 1fr 1fr 1fr}}\n.eco-tool__card{border:1px solid rgba(0,0,0,.12);border-radius:12px;padding:12px}\n.eco-tool__metric-label{opacity:.85;font-weight:600}\n.eco-tool__metric-value{font-size:1.6em;font-weight:800;margin-top:6px;line-height:1.1}\n.eco-tool__metric-sub{opacity:.85;margin-top:6px}\n.eco-tool__muted{opacity:.8}\n.eco-tool__note{margin-top:10px;opacity:.9}\n<\/style>\n\n<script>\n(function(){\n  const root = document.getElementById(\"eco-tool-ideal-gas\");\n  if(!root) return;\n\n  const $ = (k)=>root.querySelector('[data-gas=\"'+k+'\"]');\n\n  const unkEl = $(\"unknown\");\n\n  const pEl = $(\"p\");\n  const pUnitEl = $(\"pUnit\");\n\n  const vEl = $(\"v\");\n  const vUnitEl = $(\"vUnit\");\n\n  const nEl = $(\"n\");\n\n  const tEl = $(\"t\");\n  const tUnitEl = $(\"tUnit\");\n\n  const mmEl = $(\"mm\");\n\n  const calcBtn = $(\"calc\");\n  const resetBtn = $(\"reset\");\n  const errEl = $(\"error\");\n\n  const resEl = $(\"result\");\n  const outP = $(\"outP\");\n  const outV = $(\"outV\");\n  const outN = $(\"outN\");\n  const outT = $(\"outT\");\n  const outMass = $(\"outMass\");\n  const eqEl = $(\"eq\");\n\n  const R = 8.314462618; \/\/ J\/(mol\u00b7K)\n\n  function setError(msg){ errEl.textContent = msg || \"\"; }\n  function fmt(n){\n    if(!Number.isFinite(n)) return \"\u2014\";\n    const a=Math.abs(n);\n    if(a===0) return \"0\";\n    if(a<0.001 || a>=1e9) return n.toExponential(3);\n    return n.toLocaleString(undefined,{maximumFractionDigits:6});\n  }\n\n  function P_to_Pa(P, unit){\n    if(unit===\"pa\") return P;\n    if(unit===\"kpa\") return P*1000;\n    if(unit===\"bar\") return P*1e5;\n    if(unit===\"atm\") return P*101325;\n    return NaN;\n  }\n\n  function V_to_m3(V, unit){\n    if(unit===\"m3\") return V;\n    if(unit===\"l\") return V\/1000;\n    return NaN;\n  }\n\n  function T_to_K(T, unit){\n    if(unit===\"k\") return T;\n    if(unit===\"c\") return T + 273.15;\n    return NaN;\n  }\n\n  function setDisabled(){\n    const u = unkEl.value;\n    \/\/ disable only the unknown field input\n    pEl.disabled = (u===\"p\");\n    vEl.disabled = (u===\"v\");\n    nEl.disabled = (u===\"n\");\n    tEl.disabled = (u===\"t\");\n\n    [pEl,vEl,nEl,tEl].forEach(inp => inp.style.opacity = inp.disabled ? \".7\" : \"1\");\n\n    setError(\"\");\n    resEl.hidden = true;\n  }\n\n  function calculate(){\n    setError(\"\");\n\n    const u = unkEl.value;\n\n    const Praw = Number(pEl.value);\n    const Vraw = Number(vEl.value);\n    const nraw = Number(nEl.value);\n    const Traw = Number(tEl.value);\n\n    const Ppa = Number.isFinite(Praw) ? P_to_Pa(Praw, pUnitEl.value) : NaN;\n    const Vm3 = Number.isFinite(Vraw) ? V_to_m3(Vraw, vUnitEl.value) : NaN;\n    const Tk = Number.isFinite(Traw) ? T_to_K(Traw, tUnitEl.value) : NaN;\n\n    let P = Ppa, V = Vm3, n = nraw, T = Tk;\n\n    \/\/ Validate knowns\n    function need(cond, msg){\n      if(!cond){ setError(msg); resEl.hidden=true; throw new Error(\"stop\"); }\n    }\n\n    try{\n      if(u===\"p\"){\n        need(Number.isFinite(V) && V>0, \"Enter a valid volume (V).\");\n        need(Number.isFinite(n) && n>0, \"Enter a valid amount (n).\");\n        need(Number.isFinite(T) && T>0, \"Enter a valid temperature (T).\");\n        P = (n * R * T) \/ V;\n        eqEl.textContent = `P = nRT\/V = ${fmt(n)}\u00d7${fmt(R)}\u00d7${fmt(T)}\/${fmt(V)} = ${fmt(P)} Pa`;\n      } else if(u===\"v\"){\n        need(Number.isFinite(P) && P>0, \"Enter a valid pressure (P).\");\n        need(Number.isFinite(n) && n>0, \"Enter a valid amount (n).\");\n        need(Number.isFinite(T) && T>0, \"Enter a valid temperature (T).\");\n        V = (n * R * T) \/ P;\n        eqEl.textContent = `V = nRT\/P = ${fmt(n)}\u00d7${fmt(R)}\u00d7${fmt(T)}\/${fmt(P)} = ${fmt(V)} m\u00b3`;\n      } else if(u===\"n\"){\n        need(Number.isFinite(P) && P>0, \"Enter a valid pressure (P).\");\n        need(Number.isFinite(V) && V>0, \"Enter a valid volume (V).\");\n        need(Number.isFinite(T) && T>0, \"Enter a valid temperature (T).\");\n        n = (P * V) \/ (R * T);\n        eqEl.textContent = `n = PV\/RT = ${fmt(P)}\u00d7${fmt(V)}\/(${fmt(R)}\u00d7${fmt(T)}) = ${fmt(n)} mol`;\n      } else { \/\/ t\n        need(Number.isFinite(P) && P>0, \"Enter a valid pressure (P).\");\n        need(Number.isFinite(V) && V>0, \"Enter a valid volume (V).\");\n        need(Number.isFinite(n) && n>0, \"Enter a valid amount (n).\");\n        T = (P * V) \/ (n * R);\n        eqEl.textContent = `T = PV\/(nR) = ${fmt(P)}\u00d7${fmt(V)}\/(${fmt(n)}\u00d7${fmt(R)}) = ${fmt(T)} K`;\n      }\n    } catch(e){\n      return;\n    }\n\n    outP.textContent = fmt(P);\n    outV.textContent = fmt(V);\n    outN.textContent = fmt(n);\n    outT.textContent = fmt(T);\n\n    const mm = Number(mmEl.value);\n    if(Number.isFinite(mm) && mm>0 && Number.isFinite(n)){\n      const mass = n * mm;\n      outMass.textContent = fmt(mass);\n    } else {\n      outMass.textContent = \"\u2014\";\n    }\n\n    resEl.hidden = false;\n  }\n\n  function reset(){\n    unkEl.value=\"p\";\n    pEl.value=\"\"; pUnitEl.value=\"kpa\";\n    vEl.value=\"\"; vUnitEl.value=\"l\";\n    nEl.value=\"\";\n    tEl.value=\"\"; tUnitEl.value=\"c\";\n    mmEl.value=\"\";\n    setError(\"\");\n    resEl.hidden=true;\n    setDisabled();\n  }\n\n  unkEl.addEventListener(\"change\", setDisabled);\n  calcBtn.addEventListener(\"click\", calculate);\n  resetBtn.addEventListener(\"click\", reset);\n\n  setDisabled();\n})();\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Ideal Gas Law Calculator (pV = nRT) Solve for pressure, volume, moles, or temperature using the ideal gas equation. Optional: estimate gas mass from molar mass. Solve for (unknown) Pressure&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":2354,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"_links":{"self":[{"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/pages\/2523"}],"collection":[{"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/science-x.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2523"}],"version-history":[{"count":3,"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/pages\/2523\/revisions"}],"predecessor-version":[{"id":2526,"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/pages\/2523\/revisions\/2526"}],"up":[{"embeddable":true,"href":"https:\/\/science-x.net\/index.php?rest_route=\/wp\/v2\/pages\/2354"}],"wp:attachment":[{"href":"https:\/\/science-x.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}