...I have some avi files that are around 400MB for a 3-4 minutes video file. Are there any way to reduce the amount of space that the file takes without losing quality? If so, what software is recommended to do that?...
400MB per 4 minutes is only 1.6 megabytes per sec. Just H264-encoded 1080p is about 4.5 megabytes/sec, and 4k from an iPhone is 5.7 megabytes/sec. So if you are ever going to record and deal with video, you'll have to accept this and get some hard drives.
However your AVI files can likely be re-encoded to a more compressed codec while preserving almost all of the original quality. If done properly it's unlikely anyone would notice the difference.
Unfortunately AVI is a container format not a codec. The material inside the AVI could be encoded with various codecs. The task is finding an app or utility that can (a) read that content and (b) transcode it at high quality to a more compressed format.
There are many web sites advertising conversion tools, but you generally don't need those. As already mentioned Handbrake is free and works well. Since this is a Mac forum I assume you are on a Mac and have free access to iMovie. Unlike Handbrake, iMovie uses Quick Sync and can export to H264 faster.
I just did transcoding tests of a 4.16 gigabyte, 18 min 16 sec AVI file from a Panasonic AG-DVX100 camera to H264 using both iMovie and Handbrake on my 2017 iMac 27. The default Handbrake x264 settings produced a 1.5 mbps file, and I used the iMovie export settings to pick the lowest bit rate of 2 mbps.
There was minimal quality difference between the two transcoded files, and no difference between the Handbrake transcoded version vs the original AVI file.
iMovie: 309MB, 1 min 30 sec
Handbrake: 242MB, 2 min 44 sec
Note that iMovie by default will use 720p and to retain the original 4:3 aspect ratio you must press "crop", then "fit" and the output will be pillarboxed 4:3 in a 720p frame. Handbrake by default makes a 4:3 output; how that is handled depends on the player.
Despite the faster transcoding performance of iMovie, close inspection shows the Handbrake output is slightly sharper. Without further testing and experimentation I would probably use Handbrake.
In comparing the original and transcoded output, another factor is NTSC AVI content is usually interlaced. When playing that back the deinterlace behavior depends on the playback tool. By default VLC does not deinterlace, although it has several deinterlace algorithms that can be enabled. It appears that both Handbrake and iMovie deinterlace by default when transcoding. They both produce a "hard deinterlaced" output file with the deinterlacing "baked in". So when comparing the original and transcoded material you'd have to use a player like VLC which can deinterlace the original to provide an equivalent image.