How to add a license to a source-code?

For example, I have written a piece of code that is very efficient and has many commercial applications. I have published the code on my website, and I want to add a license to it.
So, can I just write that "This code is published under <this> License", or am I supposed to do something more?
And, if the license is open-source (like MIT License), then do I have to inform the publishers of the license that I am using their license?

2 Answers 2


Licencing a piece of code is as simple as that: just state that the code is under the license, and you're done. Usually it's a good idea to add author information, too. The whole point of the exercise is that any other person can unambiguously know the origin of the code and the license (thus permissions granted) for its usage. There is no formal requirement.

Yet, for ease of use, it's customary to put into the source files at the header a short copyright notice (thus license name and author) and accompany the whole source code with a COPYRIGHT or LICENSE or NOTICE file which spells out the authorship and especially the license in detail. This standard form makes it easy on two accounts:

  • each file lists at the top what license (type) it uses
  • anybody can get the full info from a dedicated file with a (semi)standardized name.

These two things make quick assessment of whether I (as user) can use the code for my purpose instead of going through a whole repository and looking at each file separately.

No open-source license will (and can) require that any user has to inform the creator. Such a condition would fail the desert-island-test and because of that, such license would not be considered open-source. Most licenses will require though that the original creator is credited at least in the form that their copyright notice is retained.

  • What's the desert-island-test? I've never heard that term. I know that a requirement to tell the publisher's of the license would make it "not open source" according to most people's definition of open source. And the publisher of the license isn't really interested.
    – gnasher729
    May 17, 2021 at 12:13
  • @gnasher729 I added a link to the debian wiki which has also the original source. Basically it means that the license right must also be possible to be exercised on a remote island where you have no communication to the outside. Thus a requirement to tell someone (the author) about you using or changing a piece of software cannot be fulfilled. Thus a requirement to get a license only on condition to tell someone or actively provide sources to s/o would make it non-free. May 17, 2021 at 12:36

It's as simple as that. All you need to do is declare the license you are using and add a copy of that license to the source repository. Note that for most licenses, you'll also need to specify the copyright holder and the year the copyright took effect in the licsece's body.

  • And practically, if someone sees your code and says "great code, but I don't like the open source license, I'll offer you gazillions for an unrestricted license" you'd want them to know where to send the money :-)
    – gnasher729
    May 17, 2021 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.