Wells Fargo will pay $4 million after the government found it charged some of its student loan borrowers illegal late fees.

The bank agreed to pay a penalty of $3.6 million to the Consumer Financial Protection Agency, according to the settlement agreement.

It also must set aside $410,000 to refund customers who were hit with illegal fees, which occurred between 2010 and 2013.

Wells Fargo (WFC) is one of the biggest private student loan lenders in the country and currently has about 1.3 million student loan customers.

Families typically turn to private lenders after a student has maxed out on federal government loans and still needs help footing the college bill. Federal loans typically carry lower interest rates than private loans, offer more consumer protections, and are available to all students regardless of their family's financial situation.

Related: Don't be fooled by student debt relief scams

The bank charged illegal late fees to certain customers who made payments on the last day of their grace period, the CFPB said. Borrowers typically get a six-month grace period after leaving school before they have to start repaying their loans.

The agency also found that for some borrowers with multiple loans, Wells Fargo processed payments in a way that maximized late fees.

Illegally charged fees, the agency said, were sometimes never refunded and the incorrect information sent to credit reporting agencies was never updated.

Related: 4 steps to paying off $100,000 in student debt

Wells Fargo said it has already stopped those practices. And some fees were charged due to a "system coding error" that has been corrected, it told the agency.

"Today's consent order with the CFPB resolves three areas of concern cited by the Bureau (CFPB) related to legacy payment procedures that were retired or improved many years ago, and addresses the impact to a small number of customers," the company said.

Wells Fargo isn't the first student loan lender to be slapped with a penalty by the CFPB. A year ago, Discover had to pay a $2.5 million penalty and refund $16 million to customers for illegal student loan practices.