How Green is Your Code?

An eye-opener to Green Computing from the Summer School at UNILAG, exploring algorithmic efficiency, the Software Carbon Intensity (SCI) equation, and the physical carbon impact of code.

Engineering Logbook

When we hear about climate change and CO2 emissions, we picture large factories releasing tons of gases, cars, ships, data centers, and unregulated incineration... but did you know the code you write too has CO2 emissions?

I know how that sounds, but hear me out: this episode is a major eye-opener to Green Computing. Last month, I was privileged to attend the Green and Sustainable Software Engineering Summer School at UNILAG. It was a 5-day event and a burst of personalities. We had participants from about 5 universities across Nigeria and facilitators from universities across Europe—professors, Drs, post-graduate students, academicians, and industry experts. At one point, we were the only undergraduates in the room, but it was a good thing. I never knew about Green Software or how code can cause the ice caps to melt faster; these people basically studied it, researched, and wrote papers on it.


The 3.7% Rule

3.7%—just think of that number. The carbon footprint of the entire global digital ecosystem accounts for about 3.7% of global emissions. It helps to think of this as the "total footprint of the internet," which includes not just the servers running in data centers, but also the cell networks transferring data and the manufacturing of billions of personal devices like smartphones and laptops.

For a bit of context, airplanes account for about 2–2.5% of global emissions.

When we exclude the heavy manufacturing footprint of hardware, the day-to-day operation of the global internet infrastructure accounts for about 1.5% to 1.8% of global emissions. This represents the pure electricity demand required to power and cool cloud data centers, transmit data across network grids, and keep end-user devices running.


Compute === Carbon

Now I know you're thinking, how does my HTML and CSS cause CO2 emissions? Well, it all comes down to how efficient your code is. For instance, a logic written in Java is way more efficient than the same logic written in JavaScript (no shade on JavaScript tbh), and this has real impact. I remember writing a logic 2 days ago in Go (GoLang) because Node.js would have been less efficient, and considering the use case of the logic, we needed it to be very fast. But away from that, what do I mean by efficiency?

Compute === Carbon

Every line of code you write translates to hardware execution. Hardware requires electricity. Electricity generation emits carbon. Therefore, inefficient code literally burns physical resources. It's not just about being slow—when a logic uses more compute than it should, it causes servers to use more energy, require more cooling, and creates a domino effect leading to real carbon being emitted. Multiply that across the millions of websites, apps, and pieces of software all around the world, and it's no longer weightless. It has real-world impact.

This problem can be broken down into various aspects, but I'd just discuss two—this might get a bit nerdy & technical, but we're all nerds here right? oh good!

1. Algorithmic Efficiency & Cyclomatic Complexity

The best way to explain this would be with another term: Cyclomatic Complexity. Let's dig in. Cyclomatic Complexity is "how hard is this code for the CPU to run?" It is a pure mathematical count of the execution paths through a function. Every time you write if, else, while, for, case, or &&, the score goes up by 1.

So when you optimize the algorithm to perform the same task with much less compute, you aren't just making it faster; you are drastically reducing the number of CPU cycles required to complete a task. Remember, compute = carbon.

2. Network and Data Efficiency

This is the Cost of Transport, because your data doesn't teleport. Moving bytes across the internet requires powering routers, switches, and cell towers. Hope you know there are literally thousands of kilometers of internet cables on the sea floor connecting continents.

Sending uncompressed data, oversized images, or bloated JSON payloads wastes energy at every node the data passes through. If your software makes identical database queries or API calls repeatedly, you are duplicating work and wasting server energy. This is where caching and other clean code techniques come in very handy.


The Software Carbon Intensity (SCI) Specification

Someone reading this might be like, "energy this, energy that, it's all theoretical." So for the super nerds in the house, here is a bit of mathematical perspective:

SCI = [(E * I) + M] / R

Ah, finally some math. This is the Software Carbon Intensity (SCI) specification equation, standardized by the Green Software Foundation.

So what do these letters actually mean for your codebase? Let’s cut the fat:

  • E (Energy Consumed): The raw electricity your code burns (kWh). Inefficient loops and complicated logic keep the CPU awake, driving this number up.
  • I (Carbon Intensity): How dirty your local power grid is (gCO2e/kWh). If your servers are running on fossil fuels, your emissions multiply. This depends on what type of energy your grid relies on—renewable or fossil fuel.
  • M (Embodied Emissions): The physical carbon cost of manufacturing the hardware. If your heavy frontend forces users to upgrade their devices, or demands oversized compute nodes such as GPUs or large RAMs instead of lean edge modules, your code is generating physical e-waste.
  • R (Functional Unit): The denominator (e.g., per 1,000 API requests, or per route mapped). This turns vague sustainability talk into an actual, measurable engineering rate you can optimize.

You can’t write a fast algorithm (optimizing E), dump it on an oversized server (inflating M), and call it green. You have to engineer the whole system.

For more practical insights, you can check out the carbon score of this blog on websitecarbon.com (PS: It's on an A-tier rating, and only 0.07g of CO2 is produced every time someone visits this web page. Feel free to check other sites).


How Does This Relate to Mechatronics & IoT?

Now I know you're thinking, how does this relate to Mechatronics? Come to think of it, there are actually more real problems caused by inefficient code.

Your Arduino, ESP32, or Raspberry Pi does more work and uses more power when your C++ runs unnecessary loops or continuously compiles bloated code—it has a direct implication on your battery. Your power pack runs down faster, and if your project uses the grid, well... I believe you should get the gist by now.

This power constraint should be one of the major things to consider when designing IoT or Robotic systems, and I'd be revealing something on it in the next episode.


Conclusion

As I bring this episode to a close, it was truly a lovely week in UNILAG (really cool campus btw), but the lessons learned will shape the way we build systems from here on.

Remember: Compute = Carbon, and your code has real-world impact.