What Is an Open Source License and Which One Should You Use?
Understand the legal side of sharing code — what open source licenses mean, why they matter, and how to pick the right one for your project.
What Is an Open Source License?
When you write code, by default you own it and nobody can legally use, copy, or change it — just like how a book you write is yours alone. An open source license changes that. It's a legal document that gives other people permission to use your code in specific ways.
Think of it like a permission slip. Without one, no one can legally touch your code. With the right license, you get to decide exactly what others can do with it: copy it freely, use it in their own projects, or even sell products built on top of it — or not.
Licenses matter because code doesn't live in a bubble. Developers share code on GitHub, pull in open source libraries, and build on each other's work. The license is the rulebook that makes all of that cooperation possible — and legal.
Why You Can't Ignore Licenses
If you put code online without a license, it's still protected by copyright. Anyone who uses it without asking is technically breaking the law — even if they didn't know better. That means companies and developers who might want to use or contribute to your project will stay away, just to be safe.
Licenses also protect you as a user. When you use someone else's open source library, the license tells you what you can and can't do with it. That clarity means you can build on other people's work with confidence, knowing exactly where you stand legally.
There are hundreds of open source licenses, but most projects only need to know about a few. Picking the right one signals to other developers how they should interact with your project — and whether it's the right fit for them.
💡 Key Insight
Without a license, your code is legally off-limits to everyone — even if you posted it publicly. Adding even the simplest open source license immediately opens the door for collaboration, reuse, and community building.
Choosing the Right License
Different licenses give different permissions. Here's how to think about the main categories:
Permissive (Use Freely)
- ✅ Use code in any project — even commercial ones
- ✅ Modify and sell the code
- ✅ No need to share your changes back
- ⚠️ Must keep the original license and credit
Examples: MIT, BSD, Apache 2.0
Copyleft (Share If You Derivative)
- ✅ Use code in any project
- ⚠️ If you modify and distribute it, you must release your changes under the same license
- ⚠️ Can create tension with proprietary products
- ✅ Ensures the open source chain stays open
Examples: GPL, AGPL, MPL
There's also one more important category — public domain (CC0), which gives up almost all rights and puts code in the absolute free public realm with no strings attached.
Here's a simple way to decide: If you want maximum adoption and don't care if companies use your code in closed products, go permissive (MIT is the safest default). If you want to make sure any improvements stay open and benefit everyone, go with a copyleft license like GPL.
Adding a License to Your Project
The most common way to add a license is to put a LICENSE file in your project root alongside your code. Here's what an MIT license file looks like — it's short, readable, and the most popular open source license in the world:
MIT License Copyright (c) 2026 Your Name Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
To add this to your project, just create a file named LICENSE (no extension) in your project folder, paste the text in, and replace "Your Name" and the year. That's it — your code now has legal permission guidelines attached to it.
On GitHub, you can also add a license through the repository settings, and it will automatically create the LICENSE file and display a badge on your repo.
Knowledge Check
Test what you learned with this quick quiz.