Who Owns the Code I Write (Graduate Student)? As a graduate student in a CS program, "Who Owns the (rights to the) Code I Write"?

I know that the answer is different depending upon:

(Case-1) I work for the University or am supported in some way (such as a TA, RA, and whether I receive financial assistance such as tuition).

(Case-2) Or I work for an employer who is paying my tuition (and thus may have some claim over the code I write while working on courses).

(Case-3) My specific case - I am paying for my tuition, so there is no party providing funds. Thus it would seem that I retain ownership in the code I write on my own time. Does it matter whether the code is written to solve a problem or assignment?

I have read my University Intellectual Property statement, (which is written in legal terminology), but seems to suggest that I would relinquish (at least some) rights in the first case. This would indicate that I would retain rights in my case (or the employer policies in Case-2).

There are similar questions (below), but they seem to answer different questions, related to (Case-1) and relationship between student, professor, and funding parties.


Ownership of the code
Sharing assignments with a potential employer
Thesis in use, potential employer wants to see source code
As indicated, this is a legal question and  not an academic one, however I do get asked this frequently by students.

Intellectual property questions are never simple. When you do work at a university, the idea that created the work may have come from a member of the academic staff. Ideas and techniques that are incorporated in the work come from classes created by other academic staff. Some of their ideas come from their education and books and papers they used. The university (their current employer) and perhaps some past employers may have contributed to that knowledge.

Then the student creates some artefact from that. Does the student wholly own everything intellectual in that artefact? Probably not, unless there is an agreement that says they do.

Without any agreement it would be for the courts to decide who owns what fraction of the intellectual property. Normally no one bothers, but when it is a valuable idea or artefact then the lawyers will follow.

There can be no simple answer to this question.