Partly. The movie takes inspiration from some actual incidents but also incorporates fictional elements for dramatic effect. So, it's not a strictly 100% true story.
Yes, it is. During World War II, the Enigma machine was a crucial part of German military communication. The Allied forces knew that if they could get hold of it, they could decrypt German messages. U - boats were used to carry these machines. The movie 'U - 571' is based on the true concept of the Allied forces' attempts to capture a U - boat with the Enigma machine on board. But in the movie - making process, there were alterations to the real story to fit the Hollywood narrative, such as changing the nationality of the crew that first captured the Enigma in the movie's version compared to what actually happened in history.