Open source · Licensing

Software Licenses Explained: MIT, Apache 2.0, GPL and How to Choose One for Your GitHub Project

Khairul Alam·November 2026·~20 min read
Open sourceSoftware licensesMITApache 2.0GPLGitHub

Every public repository carries a question that nobody asks out loud: what am I allowed to do with this code? A software license is the answer. It is a short legal document, usually a file called LICENSE in the root of the repository, that tells other people what they may do with your source code. This post explains what licenses are, reads the MIT license line by line, compares the licenses you will meet most often, and helps you choose one for your next project.

The whole post in 60 seconds
  • A license tells other people whether they may use, change, share and sell your code, and under which conditions.
  • Making a repository public does not make it open source. With no license, you keep all rights and others have no permission to reuse your code.
  • Permissive licenses (MIT, BSD, Apache 2.0) let people do almost anything if they keep your notice. Copyleft licenses (GPL, LGPL, MPL) also ask people to share their changes under similar terms.
  • MIT is short and simple. Apache 2.0 adds an explicit patent grant. GPL keeps derivative works open.
  • For learning and sample projects, MIT or Apache 2.0 is usually the easy, safe choice.
  • MIT does not make people credit you in their app. They only have to keep the copyright and license notice with the code.
  • Your license does not change the license of the libraries you depend on.
  • This is a general explanation, not legal advice.
Contents
  1. What a software license is, and why code without one is not open source
  2. A worked example: the MIT license, line by line
  3. The licenses you will meet most often
  4. Permissive or copyleft: what changes in practice
  5. Which license should you choose?
  6. LICENSE, COPYRIGHT and NOTICE: what each file is for
  7. Your license and your dependencies
  8. Add a license to your GitHub repository
  9. Common mistakes
  10. Takeaways and glossary

Not legal advice. I am a software engineer, not a lawyer. This post explains the ideas in plain words so you can read a license with confidence and pick a sensible one. For a company product, a contract, or a dispute, ask a qualified lawyer.

1. What a software license is, and why code without one is not open source

A software license is a legal document that defines what other people are allowed to do with your source code when you publish a project. When you put an Android app, a Kotlin library, a Java application or any other project on GitHub, the LICENSE file tells other developers whether they can:

No license does not mean free to use

The law gives you copyright over the code you write, automatically, the moment you write it. You do not need to register anything. So if you publish a repository with no license, the default is “all rights reserved”: nobody else may copy, change or redistribute your code without asking you.

Making the repository public changes only one thing: people can see it. GitHub’s terms let other GitHub users view and fork a public repository on GitHub, but that is all. A public repository without a license is not open source, and a careful developer or company will avoid copying it.

Analogy. Think of a photograph on a website. You can look at it. But unless the photographer says how it may be reused, you cannot print it in your own book. A license is the photographer’s note that says, “you may reuse this, if you do X.”

“Open source” also has a formal meaning. The Open Source Initiative (OSI) publishes the Open Source Definition, and a license counts as open source when it allows people to use, study, change and share the software freely. MIT, BSD, Apache 2.0, GPL, LGPL and MPL are all on OSI’s list of approved licenses.

2. A worked example: the MIT license, line by line

The MIT License is one of the most popular permissive open-source licenses, and it is a good first license to learn because it is so short. When a repository’s LICENSE file contains the MIT License, other developers can do all of this:

What someone may doAllowed?
View the source codeYes
Copy the codeYes
Modify the codeYes
Use it commerciallyYes
Include it in a paid applicationYes
Redistribute itYes
Use it in closed-source projectsYes
Sell software that contains the codeYes

The conditions are short:

In simple terms: people can use the code, even inside a commercial product, without asking the author for permission, as long as they follow the license. Here is the full text, with placeholders for the year and the copyright holder:

MIT License

Copyright (c) <year> <copyright holder>

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, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Reading it line by line

The license saysIn plain words
Copyright (c) <year> <copyright holder>Who owns the copyright, and since which year. You fill in your own name and year. This is the notice that must travel with the code.
Permission is hereby granted, free of chargeYou do not pay the author and you do not need to ask.
to use, copy, modify, merge, publish, distribute, sublicense, and/or sellThe list of permissions. Merge means combining it with your own code. Sublicense means you can pass the code on inside your own project, under your own terms, as long as the notice stays.
The above copyright notice and this permission notice shall be includedThe one real condition. Keep the notice with copies and with substantial portions of the code.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTYNo promises. If the code has a bug or loses your data, you cannot hold the author responsible.

Licenses fall on a spectrum. On the left are licenses that ask almost nothing of the people who reuse your code. On the right are licenses that require derivative work to stay open too.

Public domainCC0, Unlicense MIT / BSD keep the notice Apache 2.0 notice + patents MPL 2.0 per-file copyleft LGPL 3.0 library copyleft GPL 3.0 strong copyleft Fewest conditions for people who reuse your code Derivative work must stay open
From permissive to copyleft: the further right, the more a license asks of the people who reuse your code.

MIT: very permissive

People can use, modify, distribute and sell the code, including inside closed-source software. They keep the copyright and license notice. It is short enough to read in a minute. Examples: React and Express.js.

Apache 2.0: permissive, with patent protection

Similar to MIT, but it also gives an explicit patent grant: people who contribute code license any patents that cover their contribution, which protects users from patent claims by contributors. It also has extra duties: keep the notices, and mark the files you changed. Examples: Kubernetes, Kotlin and AndroidX.

BSD 2-Clause and 3-Clause: permissive

Very close to MIT. Commercial use and redistribution are allowed with the copyright and license notices. The 3-Clause version also forbids using the contributors’ names to promote a derived product without permission.

GPL 3.0: strong copyleft

You can use, modify and distribute the software, and even sell it. The catch: when you distribute a derivative or a combined work, you generally have to offer the corresponding source code under the GPL as well. That keeps improvements open, and it also makes GPL code hard to use in closed-source products. Examples: GIMP and the Linux kernel (which uses GPL version 2).

A close relative is the AGPL, which treats software offered over a network (a web service, for example) like distributed software.

LGPL 3.0: copyleft for libraries

Designed for libraries. A proprietary application can generally use an LGPL library, with conditions such as allowing users to replace or relink the library. Changes to the library itself have to be shared.

MPL 2.0: file-level copyleft

If you change a file that is covered by the MPL, and you distribute it, that file must stay under the MPL. But you can combine MPL files with your own proprietary code in a larger application. It is a middle path between MIT and GPL. Example: Firefox.

Unlicense and CC0: public-domain dedications

These try to give up copyright restrictions as far as the law allows. How well that works depends on the country, which is why some people prefer a permissive license like MIT instead.

4. Permissive or copyleft: what changes in practice

The practical question is what happens when someone else builds on your code. This table is a simplified summary, so read the real license before relying on it.

LicenseCan it go into a closed-source app?Must changes be shared?Explicit patent grant?
MITYesNoNo
BSD 2/3-ClauseYesNoNo
Apache 2.0YesNo (keep notices, mark changed files)Yes
MPL 2.0Yes, as part of a larger workYes, for the MPL-covered filesYes
LGPL 3.0Yes, when used as a library, with conditionsYes, for the library itselfYes
GPL 3.0Generally no: the combined work becomes GPL when distributedYes, when distributingYes
Free does not mean no rules

Every one of these licenses has conditions. Even MIT has one: keep the notice. “Open source” means you may reuse the code, not that you may ignore the license.

5. Which license should you choose?

Start from your goal, not from the license names.

Your intentionGood fit
Anyone can reuse the code, no fussMIT
Commercial use, plus an explicit patent grantApache 2.0
Improvements must always stay open sourceGPL 3.0
An open-source library that proprietary apps may still useLGPL 3.0
Others may change your files, but the files stay open, and larger projects can stay proprietaryMPL 2.0
Give up your rights as far as the law allowsUnlicense or CC0
My default for learning and sample projects

For educational Android, Kotlin and Java projects, such as architecture examples (MVC, MVP, MVVM, MVI, Redux, VIPER), small apps and tutorials, I would choose MIT. Choose Apache 2.0 instead if you want the explicit patent grant and do not mind the extra notice rules.

Questions to ask yourself

  1. Do I mind if a company uses this in a closed product? If not, pick a permissive license. If yes, look at the GPL family.
  2. Could patents be involved? If yes, Apache 2.0 (or MPL, or GPL 3.0) spells out the patent permission. MIT does not mention patents.
  3. Is it a library or an application? Libraries that you want widely adopted usually use a permissive license or the LGPL.
  4. Are other people contributing? Pick the license before accepting contributions. Changing it later usually needs everybody’s agreement.

6. LICENSE, COPYRIGHT and NOTICE: what each file is for

File or linePurpose
LICENSEThe legal permissions and restrictions. This is the file GitHub looks for, and it shows the license name on the repository page.
Copyright lineWho owns the copyright and from which year. In the MIT license it is the first line, Copyright (c) 2026 Your Name. Some projects also keep a separate COPYRIGHT file.
NOTICEOften used with Apache 2.0 to carry attribution and other notices that must be passed on with the software.
SPDX headerA one-line tag at the top of a source file that names its license, for example // SPDX-License-Identifier: MIT. Tools can read it.

Also mention the license in your README, with a link to the LICENSE file. People read the README first.

7. Your license and your dependencies

A repository can contain or use third-party code that has different licenses. Putting an MIT license on your repository does not change the license of those libraries. Each dependency stays under its own terms, and you have to follow them.

For an Android app this matters a lot, because a typical project pulls in dozens of libraries, and many of them (AndroidX, Kotlin, OkHttp, for example) use Apache 2.0, which asks you to keep their notices. That is why many apps have an “Open source licenses” screen; Google’s OSS licenses Gradle plugin can generate one for you.

Can I mix code under different licenses?

SituationUsually
MIT, BSD or Apache 2.0 code inside a GPL 3.0 projectFine. Keep their notices.
GPL code inside an MIT project that you distributeThe combined work must follow the GPL, so the “MIT project” stops being only MIT.
Apache 2.0 code and GPL 2.0-only code togetherNot compatible. Apache 2.0 and GPL 3.0 are compatible.
Code with no licenseDo not copy it. You have no permission.

When in doubt, check the dependency’s license before you ship, and keep a list of what you use.

8. Add a license to your GitHub repository

On the GitHub website

  1. Open your repository and choose Add file, then Create new file.
  2. Type LICENSE as the file name. GitHub then shows a Choose a license template button.
  3. Pick a license, fill in your name and the year, and commit the file.

When you create a new repository, you can also choose a license in the creation form.

From the command line

# Copy the text of the license you chose into a file called LICENSE, then:
git add LICENSE
git commit -m "Add MIT license"
git push

GitHub detects standard license files and shows the license name in the repository sidebar. For a Maven or Gradle library, also declare the license in the build metadata, for example in pom.xml:

<licenses>
  <license>
    <name>MIT License</name>
    <url>https://opensource.org/license/mit</url>
  </license>
</licenses>

9. Common mistakes

Things that cause trouble
  • Publishing with no license and assuming people may reuse it. They may not.
  • Copying a license and leaving someone else’s name and year in the copyright line.
  • Believing MIT forces people to credit you in their app. It only requires keeping the notice with copies and substantial portions of the code. Nobody has to mention your name on a splash screen or your GitHub profile.
  • Pulling GPL code into a permissive project without noticing what that does to the whole combined work.
  • Forgetting dependencies. Your license covers your code, not theirs.
  • Expecting to take rights back. If you change the license later, people who already received the code under the old one generally keep the rights they were given.
  • Assuming a license covers names and logos. Most software licenses are about the code. Trademarks are a separate matter, and Apache 2.0 says so explicitly.

10. Takeaways and glossary

TermIn plain words
CopyrightThe automatic legal right of the author to control copying and reuse of their work.
LicenseThe author’s written permission to do certain things with the work, under stated conditions.
Open sourceSoftware under a license that lets everyone use, study, change and share it.
Permissive licenseA license with few conditions, mainly “keep the notice” (MIT, BSD, Apache 2.0).
CopyleftA license that requires derivative work to be shared under similar terms (GPL, LGPL, MPL).
Derivative workNew work built from, or including, existing code.
Proprietary / closed sourceSoftware whose source code is not shared and whose use is restricted by its owner.
Patent grantA promise not to sue users over patents that cover the code you contributed.
AttributionKeeping the required copyright and license notices with the code.
SPDX identifierA standard short name for a license, such as MIT or Apache-2.0.
← Back to all writing