If you sign an invention assignment agreement (IAA) with a university, it will own inventions that fall within the scope of the agreement. Universities typically require employees including faculty, staff, and graduate students to sign these agreements. Even if a university employee doesn't sign an IAA, the university might have "shop rights" or copyright ownership of developments made with university resources or within the scope of employment.
Undergraduate students generally are not employed by the university and are not required to sign IAAs, so they keep the rights to their own inventions. (Though there can be some tricky situations where significant university resources are used.)