title: CO2.js: An Open Library for Digital Carbon Reporting
url: https://branch.climateaction.tech/issues/issue-4/normalising-digital-carbon-reporting/
hash_url: dbdfbdab3a63c31e36fcb412f3b4b0e0

<p>Uploading and downloading the bits and bytes that make up the internet uses <em>a lot</em> of electricity. Breaking the internet down to a systems level, data transfer over networks accounts for an <a href="https://sustainablewebdesign.org/calculating-digital-emissions/">estimated 14% of the web’s total electricity</a> consumption. Networks are also globally distributed, meaning that the bytes you downloaded to render this web page in your browser are probably passed through several different electricity grids. Those grids are made up of different mixes of green and fossil fuel energy.</p>



<p>Being able to measure and account for the emissions of digital services is increasingly important, especially as carbon emissions reporting becomes a mandated part of business operations. Outside of the corporate space, consumers are also increasingly demanding greater visibility of CO2 information for the goods and services they use.</p>



<p>In order to meet the growing demands for reporting and transparency, developers need a way to measure the carbon emissions associated with the apps, sites, and software they build. On the server side, we’re seeing more providers build carbon reporting into their platforms. However, on the application side, it’s largely up to developers themselves to implement solutions. That’s where libraries like CO2.js come in handy, providing a set of research-based, standard calculations that enable developers to quickly add carbon awareness to their products and projects.</p>



<h2>What is CO2.js?</h2>



<p><a href="https://github.com/thegreenwebfoundation/co2.js">CO2.js</a> is a JavaScript library that allows developers to estimate the emissions associated with their apps, websites and software. At its core, CO2.js takes an input of data, in bytes, and returns an estimate of the carbon emissions produced to move that data over the internet. It can be run in Node.js server environments, in the browser, as well as on some serverless and edge compute runtimes.</p>



<h2><strong>Why use it?</strong></h2>



<p>Being able to estimate the carbon emissions associated with digital activities can be of benefit to both development teams and end users. The carbon emissions of the internet are something that is abstract, and out of sight. Using CO2.js allows these emissions to be surfaced, visualised, and presented in ways that make it easier for people to comprehend and act on.</p>



<p>The possible uses for CO2.js are wide and varied. It can be used in user-facing applications to give visibility to the carbon impact of user activity in the application. Users uploading files, or downloading content, could be notified of the impacts of those tasks. Large, carbon-intensive, data transfers could also be blocked or limited. Users could also have the option to set a carbon budget for their browsing or use of an app, website, or online service.</p>



<p>Behind the scenes, developers could look to use CO2.js as part of their deployment workflow. In the same way that web developers might set a <em>performance budget</em> for their site, <a href="https://css-tricks.com/reduce-your-websites-environmental-impact-with-a-carbon-budget/">a carbon budget could also be used</a>. If a website or app exceeds a threshold for carbon intensity, then an alert can be raised or a new deployment can be blocked. The data from CO2.js can also be used as part of internal monitoring tools and dashboards.</p>



<p>Office managers and sustainability teams could also use CO2.js to track the carbon intensity of data usage within an office environment. Plugging network data usage into CO2.js can allow for monitoring and reporting on the digital usage footprint of an organisation or business.</p>



<h2>CO2.js today</h2>



<p>CO2.js can do more than <em>just</em> estimate the carbon impact of data transfer on the internet. It also includes functions that use The Green Web Foundation’s <em>greencheck</em> API to determine if a website or domain is hosted on a green web host.</p>



<p>In the wild, the CO2.js package already receives close to 2000 weekly downloads on NPM. It is actively used by website testing tools like <a href="https://ecograder.com/">Ecograder</a>, and performance tools like <a href="http://SiteSpeed.io">SiteSpeed.io</a> to track and display website carbon emissions for users. Website analytics service <a href="https://withcabin.com/">Cabin</a> also use CO2.js to calculate emissions for page views and historical analysis of CO2 for each page.</p>



<figure class="wp-block-image size-large"><img loading="lazy" src="https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8-1024x428.png.pagespeed.ic.1HClVH965i.png" alt="" class="wp-image-1698" srcset="https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8-1024x428.png.pagespeed.ic.1HClVH965i.png 1024w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8-300x125.png.pagespeed.ic.9qZR3hPWHI.png 300w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8-768x321.png.pagespeed.ic.glvEqo2nt8.png 768w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8-1536x641.png.pagespeed.ic.nnVe1_DjTF.png 1536w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-8.png.pagespeed.ic.zEH60AU5VC.png 2000w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>Screenshot for the <a href="http://sitespeed.io/" target="_blank" rel="noreferrer noopener">SiteSpeed.io</a> sustainability plugin.</figcaption></figure>



<figure class="wp-block-image size-large"><img loading="lazy" src="https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-9-1024x547.png.pagespeed.ic.slGUmxUU6_.png" alt="" class="wp-image-1699" srcset="https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-9-1024x547.png.pagespeed.ic.slGUmxUU6_.png 1024w, https://branch.climateaction.tech/wp-content/uploads/2022/08/image-9-300x160.png.pagespeed.ce.LL_EBYDoT1.png 300w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-9-768x410.png.pagespeed.ic.HgzumbgWzi.png 768w, https://branch.climateaction.tech/wp-content/uploads/2022/08/ximage-9.png.pagespeed.ic.sMcfWZTX9Y.png 1497w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>Screenshot of a <a href="http://sitespeed.io/" target="_blank" rel="noreferrer noopener">SiteSpeed.io</a> dashboard in Grafana.</figcaption></figure>



<figure class="wp-block-image size-large"><img loading="lazy" src="https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot-1024x771.png.pagespeed.ic.-Sd-9Uwv0Y.png" alt="Screenshot of the Cabin website analytics dashboard showing page view carbon emissions." class="wp-image-1934" srcset="https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot-1024x771.png.pagespeed.ic.-Sd-9Uwv0Y.png 1024w, https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot-300x226.png.pagespeed.ic.MYG9q4FK8s.png 300w, https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot-768x578.png.pagespeed.ic.zLfxHplGB2.png 768w, https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot-1536x1156.png.pagespeed.ic.b5hLWwBd-t.png 1536w, https://branch.climateaction.tech/wp-content/uploads/2022/09/xcabin-screenshot.png.pagespeed.ic.4geNSFc233.png 2000w" sizes="(max-width: 1024px) 100vw, 1024px"><figcaption>Screenshot of the Cabin website analytics dashboard showing page view carbon emissions.</figcaption></figure>



<p>CO2.js is covered by an Apache 2.0 license. This allows for the library to be used in digital tools and services. Since the <a href="https://github.com/thegreenwebfoundation/co2.js">code is kept on GitHub</a>, and is also open for anyone to review, fork, modify, and contribute to. As we’ll touch on a little later, any datasets and figures used in CO2.js are also open, keeping with the themes of open-source, open data, and Open Climate.</p>



<h3>Models available for estimating digital carbon</h3>



<p>There are a few different models that can be used to measure digital carbon emissions. CO2.js includes two of these – the OneByte model, and the Sustainable Web Design model.</p>



<p><strong>Sustainable Web Design</strong></p>



<p>By default, CO2.js uses the <a href="https://sustainablewebdesign.org/calculating-digital-emissions">Sustainable Web Design model</a> developed by a collaboration of <a href="https://www.wholegraindigital.com/">Wholegrain Digital</a>, <a href="https://www.mightybytes.com/">Mightybytes</a>, <a href="https://www.medina-works.com/">Medina Works</a>, <a href="https://ecoping.earth/">EcoPing</a>, and the <a href="https://www.thegreenwebfoundation.org/">Green Web Foundation</a>. It is designed for helping understand the environmental impact of websites, as well as digital products and services.</p>



<p>This model segments the system (the internet) into four parts – data centres, networks, end-user devices, and device production. Based on the bytes passed to it, the Sustainable Web Design model calculates the energy used by each part of the system. These figures are then converted to carbon estimates using the global carbon intensity of electricity from the <strong><a href="https://ember-climate.org/insights/research/european-electricity-review-2022/">Ember annual global electricity review</a></strong>.</p>



<figure class="wp-block-image"><img src="https://fershad.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F1aa832d9-d1ba-4486-93a0-6d08a0ffa7ff%2FUntitled.png?table=block&amp;id=000ea413-3041-4f09-9e2a-2277d69ba268&amp;spaceId=b4cfdeca-5b5d-4325-a3da-7980b01e614c&amp;width=1920&amp;userId=&amp;cache=v2" alt=""><figcaption>The breakdown of system segments used for calculations in the Sustainable Web Design model.</figcaption></figure>



<p>The carbon intensity of electricity figures used by the Sustainable Web Design model includes full lifecycle emissions. This includes upstream methane, supply-chain and manufacturing emissions, and includes all gases, converted into CO2 equivalent over a 100-year timescale.</p>



<p><strong>OneByte Model</strong></p>



<p>Additionally, CO2.js also allows developers to use the OneByte model introduced by The Shift Project in their report on CO2 emissions from digital infrastructure, <strong><a href="https://theshiftproject.org/en/lean-ict-2/">Lean ICT: for a sober digital</a></strong>. This model returns a number for the estimated carbon emissions given the number of bytes sent over the wire. It has been used for estimating the impact of video streaming, file downloads and websites.</p>



<p><strong>How the models differ</strong></p>



<p>These models return slightly different results since they apply different system boundaries as part of their calculations. Tom Greenwood has written <a href="https://www.wholegraindigital.com/blog/website-energy-consumption/">a terrific blog post</a> explaining system boundaries and how they impact carbon estimates.</p>



<p>The OneByte model, as it has been implemented in CO2.js, applies narrow system boundaries – datacenter and network only. It takes a top-down approach to calculations, returning a single carbon emissions result based on a given input. It should be noted that the original model used in the Lean ICT report did have broader systems boundaries. However, when the model was included in CO2.js a judgement call was made to reduce its scope. You can read more about why in <a href="https://github.com/thegreenwebfoundation/co2.js/issues/68">this GitHub issue</a>.</p>



<p>On the other hand, the Sustainable Web Design model has a broader system boundary (explained above). It takes a more complex, but detailed, bottom-up approach. By using a wider system boundary, the Sustainable Web Design model provides a more comprehensive carbon estimate. This also means that segmented estimates can be produced for each part of the system, allowing for greater granularity and flexibility.</p>



<p>As a result, the carbon estimates returned when using the OneByte model will be lower than those from Sustainable Web Design for the same amount of data transfer.</p>



<h2>What’s planned for CO2.js?</h2>



<p>CO2.js will evolve alongside the continued research into the environmental impact of the digital sector. As new data and methodologies emerge, the library will be updated to provide the best possible source of digital carbon estimates for developers. Being an <a href="https://github.com/thegreenwebfoundation/co2.js/issues">open-source library</a>, contributions from the community are always welcome.</p>



<p>Alongside this, making it easier for developers to start using CO2.js is a key priority. Building flexibility into the library, so that it can be used across JavaScript environments and frameworks, will hopefully empower more developers to build carbon intelligence into their tools, platforms, and services. Work on this has already begun, with the <a href="https://github.com/thegreenwebfoundation/co2.js/blob/main/CHANGELOG.md#0100-2022-06-27">recent v0.10.0 release of CO2.js</a> making it much easier to use the library in both node and the browser with ESM, CJS and IIFE build.</p>



<p>In the near term, there are a few more updates planned:</p>



<h3>Sensible and extensible defaults</h3>



<p>Each carbon estimation model comes with a set of constants that calculate electricity use and carbon emissions. Allowing users to be able to adjust these constants will enable more contextually accurate results to be returned. For example, a developer whose app runs on a server based in Norway should be able to update the CO2 per kilowatt-hour constant to reflect the carbon intensity of the Norwegian electric grid.</p>



<p>Taking it further, it may also be possible for developers to use the Sustainable Web Design model to update the constants for website caching and return visitors. This would allow them to generate website carbon estimates that are more accurate and appropriate for the site they are analysing.</p>



<h3>Bring in average and marginal carbon intensity data</h3>



<p>Sourcing carbon intensity data shouldn’t be the remit of developers. For that reason, CO2.js now includes yearly average grid intensity data from <a href="https://ember-climate.org/data/data-explorer/">Ember</a>, as well as marginal intensity data from the <a href="https://unfccc.int/">UNFCCC</a> (United Nations Framework Convention on Climate Change).</p>



<p>Average emissions intensity uses the fuel mix of the entire electricity grid and can be used to derive estimates for the carbon footprint of a digital product or service. You’ll see average intensity used in the majority of carbon reporting standards and tooling. This makes it useful if you were to use CO2.js to feed in data to other carbon reporting tools.</p>



<p>Marginal intensity, on the other hand, looks at where the additional electricity to power a device, product or service would come from. In almost all cases it would be from a fossil-fuel power source, and so marginal intensity figures tend to be higher than average intensity figures. The <a href="https://greensoftware.foundation/">Green Software Foundation</a> is one group that uses marginal intensity as part of its specification.</p>



<p>The team over at Electricity Maps have two great blog posts <a href="https://electricitymaps.com/blog/marginal-emissions-what-they-are-and-when-to-use-them/">explaining the concepts</a> and why you might <a href="https://electricitymaps.com/blog/marginal-vs-average-real-time-decision-making/">use one over the other</a>.</p>



<p>Enabling developers to access this data, and use it with the models available in CO2.js, is a key step toward generating more accurate carbon estimates.</p>



<h3>Reducing the barrier to use</h3>



<p>To accompany these changes, <a href="https://developers.thegreenwebfoundation.org/">a new developer documentation website</a> has been created for CO2.js and some of the other open-source libraries maintained by The Green Web Foundation. Providing an easy-to-digest, accessible set of tutorials and guides will hopefully enable more developers to start using CO2.js in their work. The documentation site will grow with time and as new capabilities are added to the library.</p>



<h2>Making carbon reporting accessible</h2>



<p>The possible uses for CO2.js are wide and varied, and the data produced can play an important role in educating stakeholders and enabling more climate-conscious decisions to be made when creating digital products and services.</p>



<p>If you are using (or do end up using) CO2.js in production then The Green Web Foundation would love to hear from you! Use the <a href="https://www.thegreenwebfoundation.org/support-form/">contact form</a> on their website to get in touch.</p>
