<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn" -->

---
title: Operators of death: checked arithmetic in Rust —...
description: An explainer on how Rust's fixed-width integer types can overflow, and why the default behaviour differs between dev builds (panic) and release builds (silent...
canonical: https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Operators of death: checked arithmetic in Rust — Bitfield Consulting | daily.dev
og:description: An explainer on how Rust's fixed-width integer types can overflow, and why the default behaviour differs between dev builds (panic) and release builds (silent...
og:url: https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn
og:image: https://api.daily.dev/og/posts/rUIynDmYn.png
og:image:alt: Operators of death: checked arithmetic in Rust — Bitfield Consulting
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Operators of death: checked arithmetic in Rust — Bitfield Consulting

**[Bitfield Consulting](https://daily.dev/sources/bitfieldconsulting)** · 15 min read · 5 upvotes · 0 comments

## Summary

An explainer on how Rust's fixed-width integer types can overflow, and why the default behaviour differs between dev builds (panic) and release builds (silent wrapping). The piece argues that relying on the default +, -, *, /, %, << and >> operators is a footgun, since overflow behaviour changes depending on build profile and is easy to overlook. Instead it walks through Rust's explicit arithmetic methods—checked_add, overflowing_add, wrapping_add, saturating_add and strict_add—explaining when each is appropriate, with a spacecraft-thrust example for saturating arithmetic and a radiation-machine analogy to illustrate the stakes of unhandled overflow. It also mentions the overflow-checks Cargo.toml setting and a Clippy lint (arithmetic_side_effects) that flags use of the raw operators.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://bitfieldconsulting.com/posts/operators-of-death>

## Questions this post answers

### What happens when a u8 addition overflows in a Rust release build versus a dev build?

In a dev build, Rust panics at runtime with an 'attempt to add with overflow' error, stopping the program. In a release build, overflow checks are disabled by default and the value silently wraps around to the minimum value, so 250 + 6 for a u8 produces 0 instead of an error or the mathematically correct 256.

_Developers hardening numeric code against overflow bugs can track Rust arithmetic gotchas like this on daily.dev._

### What is the difference between checked_add, wrapping_add, saturating_add, and strict_add in Rust?

checked_add returns Some(answer) or None if overflow occurs, useful when an overflowing result should be discarded. wrapping_add always wraps around on overflow without signaling it, useful for counters. saturating_add clamps the result to the type's maximum value, useful for things like a thrust setting that shouldn't wrap. strict_add panics on overflow, signaling an unrecoverable bug.

_When choosing overflow behavior for a calculation, developers compare these Rust methods via daily.dev before committing to one._

### How can I make Rust check for arithmetic overflow in release builds?

Set the overflow-checks option in the relevant profile section of Cargo.toml, such as under [profile.release], to enable the same overflow panics that dev builds provide by default. This adds extra size and runtime cost to the compiled program because every arithmetic operation gets a runtime check, so it's a trade-off rather than a default choice.

_Teams weighing safety versus performance for release builds can research trade-offs like this on daily.dev._

## Similar posts on daily.dev

- [Rust language adds algebraic floating-point methods](https://daily.dev/posts/rust-language-adds-algebraic-floating-point-methods-jimyxkos8) · InfoWorld · 1 upvotes · 0 comments
- [Faster floating point math with Rust’s new API](https://daily.dev/posts/faster-floating-point-math-with-rust-s-new-api-zyoed6fm9) · Lobsters · 0 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#rust](https://daily.dev/tags/rust)

[View this post on daily.dev](https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Operators of death: checked arithmetic in Rust — Bitfield Consulting","url":"https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn"},"datePublished":"2026-09-15T08:52:17.881Z","dateModified":"2026-09-15T08:52:43.967Z","description":"An explainer on how Rust's fixed-width integer types can overflow, and why the default behaviour differs between dev builds (panic) and release builds (silent...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c90f86d1775d7aefb05de526e81b4b2e?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c90f86d1775d7aefb05de526e81b4b2e?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Bitfield Consulting","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Bitfield Consulting","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/47364ed1cd4f42b289127844bad2b204","url":"https://daily.dev/sources/bitfieldconsulting"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,rust","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Bitfield Consulting","item":"https://daily.dev/sources/bitfieldconsulting"},{"@type":"ListItem","position":3,"name":"Operators of death: checked arithmetic in Rust — Bitfield Consulting"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/operators-of-death-checked-arithmetic-in-rust-bitfield-consulting-ruiyndmyn#faq","mainEntity":[{"@type":"Question","name":"What happens when a u8 addition overflows in a Rust release build versus a dev build?","acceptedAnswer":{"@type":"Answer","text":"In a dev build, Rust panics at runtime with an 'attempt to add with overflow' error, stopping the program. In a release build, overflow checks are disabled by default and the value silently wraps around to the minimum value, so 250 + 6 for a u8 produces 0 instead of an error or the mathematically correct 256. Developers hardening numeric code against overflow bugs can track Rust arithmetic gotchas like this on daily.dev."}},{"@type":"Question","name":"What is the difference between checked_add, wrapping_add, saturating_add, and strict_add in Rust?","acceptedAnswer":{"@type":"Answer","text":"checked_add returns Some(answer) or None if overflow occurs, useful when an overflowing result should be discarded. wrapping_add always wraps around on overflow without signaling it, useful for counters. saturating_add clamps the result to the type's maximum value, useful for things like a thrust setting that shouldn't wrap. strict_add panics on overflow, signaling an unrecoverable bug. When choosing overflow behavior for a calculation, developers compare these Rust methods via daily.dev before committing to one."}},{"@type":"Question","name":"How can I make Rust check for arithmetic overflow in release builds?","acceptedAnswer":{"@type":"Answer","text":"Set the overflow-checks option in the relevant profile section of Cargo.toml, such as under [profile.release], to enable the same overflow panics that dev builds provide by default. This adds extra size and runtime cost to the compiled program because every arithmetic operation gets a runtime check, so it's a trade-off rather than a default choice. Teams weighing safety versus performance for release builds can research trade-offs like this on daily.dev."}}]}
```

