There are a lot of different reasons why you would want to add a license to your code. You may not want anyone to be able to use or distribute your code. You might only want it to be used in non-commercial products, or only allow your neighbour to include it in his product because you accidentally let his pet hamster out of the house (who never did come back).
The open source community is growing. More and more developers are publishing their code online to websites like GitHub, SourceForge and CodePlex. As with publishing anything to the internet you should be wary and know what your rights are (especially when intellectual property laws can be a bit ambiguous).
If you want to find a bit more about publishing your code online then my co-worker Sam wrote an interesting article on comparing the Top 5 Free Hosted Version Control Sites.
1. MIT (Massachusetts Institute of Technology) License
The true open-source license. Do what-ever you like with the code/software, just make sure you give the author the proper attribution. The license must appear in every copy or substantial portions of the software but nobody can hold you liable if any issues arise from using the software. More information and a copy of the license can be found here.
2. Apache License 2.0
Similar to MIT License but you can not use any of the work under the original authors trademark. It applies patent protection for the original author and later contributors, and restricts the use of the original product’s name
3. GPL (General Public License)
This is the most widely used license but also one to be wary of. It gives everyone the ability to use, modify, distribute and run the software. It enforces CopyLeft which means that anyone who distributes this code (whether it has been modified or not) must enforce the same rights on that work. For personal use you may include this software, but as soon as you distribute your modified software it has to use the GPL license – meaning you have to make your product open-source and every user will gain the same rights that you had. This is why it is known as a viral license.
If you want to have a less viral license then you can use the Lesser General Public License LGPL. This permits the use of a library or a jar in proprietary programs and protects your code under similar rules to GPL, but does not force any code outside of your own to be released under the same license. Your distributed code/library, whether it is modified or not must still retain its LGPL license.
The Affero General Public License AGPL tightens up the GPL license by explicitly defining a ‘grey area’ in the GPL. This means any code that is run on a server must still be available for distribution to the people who use that server.
4. Artistic License 2.0
There are some licenses like the Artistic License which are preferred by certain communities. This one in particular is used by Perl developers. The Artistic License states that modified versions of the software do not prevent the users from running the standard version.
The Parrot Virtual Machine uses this license.
5. EPL (Eclipse Public License) 1.0
This license allows commercial use of the software without the recipient having to pay. It features a weaker Copyleft enforcement than the GNU license. It allows people to use, modify, copy and distribute the code and modified versions. Some cases state that the modifications must be published. EPL requires that anyone distributing the work grant every recipient a license to any patents that they might hold that cover the modifications they have made.
This license is not compatible with the GNU license so any two works combined from these two licenses cannot be distributed.
6. BSD (Berkeley Software Distribution) Licenses
These are a family of licenses which have varying clauses. Two of the GPL compliant licenses are the Simplified BSD license (2-clauses) and the New BSD license (3-clauses). The only differences between the two are that the Simplified version omits the non-endorsement clause. It also adds a further disclaimer about views and opinions expressed in the software. These licenses impose the minimal restrictions on the redistribution of covered software so it is in contrast to Copyleft.
Berkeley Software Distribution uses this license.
7. No license
You do not legally have to add a licence. Not having a license does not mean you are opting out of copyright laws it USUALLY means that the default copyright laws apply. You should double check with a few of your legal buddies first before proceeding down this route, but generally you retain all rights to your source code and nobody else may: reproduce, distribute, or create derivative works from your work. You can grant some or all of these rights explicitly to other parties if you wish to.
That is to only name a few of the major licenses out there. There are more that may be more specific. If you want to learn any more about these licenses and others check out http://opensource.org/licenses.