Is code protected by copyright?
Yes, automatically, from the moment it is written, in every country party to the Berne Convention. No registration, no notice, no LICENSE file is required. Copyright protects the expression, the code as written, not the idea, the algorithm, or the functionality. Patents cover some of that ground; trade secrets cover the rest.
The question gets asked because code does not feel like a book or a song, and copyright law was written with books and songs in mind. It applies anyway, and it applies more automatically than most developers assume.
What copyright protects in code
The expression. The specific source code you wrote, its structure, its organisation, its comments, and to a contested degree its non-literal elements like architecture and sequence. Compiled binaries are protected as copies of the source.
It arises the moment the code is fixed in a tangible form, which for our purposes means the moment it is saved. There is no application, no fee, no notice, no LICENSE file. A private repository with no licence text in it is fully copyrighted. So is a gist. So is a snippet in a chat.
This is the foundation everything else on this site rests on. A licence, open source or commercial, is permission granted on top of copyright. If there were no copyright there would be nothing to license.
What copyright does not protect
Ideas, procedures, processes, systems, methods of operation, concepts, principles, discoveries. That list is close to the statutory wording and it is long on purpose.
So: the algorithm is not protected, the implementation is. The idea of a spreadsheet is not protected, the code of a particular spreadsheet is. The functionality is not protected, the code that delivers it is. A competitor who reads your code and writes their own that does the same thing has, generally, not infringed your copyright.
Where the line falls between protected expression and unprotected function is the subject of decades of litigation and is not settled. For working purposes: your code is yours, your ideas are not exclusively yours, and copyright is a weaker shield for software than developers hope and a stronger one than they fear.
Copyright, patent, trade secret
Three different rights, protecting three different things, often over the same code.
copyright patent trade secret
───────── ────── ────────────
protects the expression the invention the secret
arises automatically by grant by keeping it
requires nothing application reasonable secrecy
lasts decades limited term while secret
lost by nothing expiry disclosure Copyright protects the code as written. A patent, where one can be obtained, protects a novel functional method regardless of how it is implemented, and software patents are granted narrowly and unevenly across jurisdictions. A trade secret protects anything confidential with economic value, which describes almost all private code, for as long as it stays confidential.
Most private source code is protected by copyright and trade secret at once. Publishing it keeps the copyright and ends the trade secret.
┌─ WORTH CHECKING ─────────────────────────────────────────────────────┐ │ │ │ Private, finished, owned by you: $500+ each to AI labs. │ │ │ │ [ See what my repos are worth ] │ │ │ └──────────────────────────────────────────────────────────────────────┘
Who is the author
Whoever wrote it, by default. That default is displaced in two common cases.
Employment. Code written by an employee in the course of employment belongs to the employer, in most jurisdictions, without any clause needed.
Contract. Code written by a contractor belongs to the contractor unless a contract says otherwise, and contracts usually do. Assignment clauses and work made for hire clauses move ownership; their absence leaves it with the developer, who grants the client an implied licence to use the work.
AI-assisted code is the new case. The US Copyright Office’s position is that output generated entirely by a model, with no human authorship, is not protectable. Code where a person made real creative choices, in writing, selecting, arranging, or substantially editing, can be. Where a heavily model-assisted repository falls is being decided case by case, and it is worth being conservative about claiming ownership of code you did not meaningfully write.
The practical test for all three is the same: can you say, without hedging, that you hold the copyright. That question is worked through in who owns the code you wrote for a client and work for hire versus license.
Where a licence fits
Copyright says nobody may copy, modify, or distribute your code. A licence says: except on these terms.
Every open source licence is a standing permission on top of copyright, which is why relicensing is possible for future versions but not for copies already distributed. The permission was granted; the copyright was kept. Adding a LICENSE file to a repository is covered in how to add a license to a GitHub repository, and what the permissive default actually permits is in the MIT license.
A commercial licence is the same structure with a fee. A licence to an AI lab to train on your code is the same structure again: the owner keeps the copyright, grants a non-exclusive permission, and can grant it again to someone else.
Why “private and copyrighted” is the state that has value
Put the pieces together.
Your unpublished code is fully copyrighted, automatically, and it is also a trade secret. Nobody has a copy. Nobody has permission. That is the strongest position a body of code can be in, and it is the default position of every private repository you own.
Publishing it under an open licence keeps the copyright and grants the world permission, permanently. That is a fine thing to do on purpose. It is also, once done, the end of any licensing value in that code, because the permission has been given away and the copies have been taken.
Code that stayed private still has all of it. That is the code labs pay to license, precisely because copyright and privacy together mean nobody else can supply it. The mechanics are in can you license private repositories.
What to read next
- Who owns the code you wrote for a client, the authorship question in practice
- The MIT license, what a permissive licence actually grants
- Can you license private repositories, what unpublished copyright is worth
Common questions
- Do I need to register copyright in my code?
- Not to own it. In the US, registration is required before you can sue over a US work and is a precondition for statutory damages and legal fees, so it matters if you expect to enforce. Elsewhere registration systems are mostly absent or optional.
- Do I need a copyright notice in each file?
- No. Notices have not been required for protection for decades. They remain useful as a signal and as evidence of a claim date, and some licences ask you to preserve them, but their absence changes nothing about ownership.
- Can you copyright an algorithm?
- No. Copyright covers expression, not ideas, procedures, processes, systems, or methods of operation. An algorithm is a method. A specific implementation of it is expression and is protected; the algorithm itself is not.
- Is AI-generated code copyrighted?
- Output generated entirely by a model with no human authorship is, on the current position of the US Copyright Office, not protectable. Code where a human made creative choices in writing, selecting, arranging, or substantially editing it can be. The line is being drawn case by case.
- What is the difference between copyright and a licence?
- Copyright is the ownership. A licence is permission granted by the owner to do things copyright would otherwise prohibit. Every open source licence, every commercial licence, and every licence to an AI lab sits on top of copyright; none replaces it.