Let be a finite field with q elements and , two distinct positive integers such that . Suppose that and are two primitive elements of and , respectively. Let and denote the trace function from to for . We define a cyclic code where In this paper, we use Gauss sums to investigate the weight distribution of and prove that it has at most four nonzero weights if and . Furthermore, we get a class of three-weight cyclic codes if . Some optimal or nearly optimal cyclic codes are presented.