---
source: https://iinventedlight.com/library/notes/rust-variables-and-mutability.md
title: "Rust variables: immutability by default, mut, and constants"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Project Developers); MIT OR Apache-2.0 (The Rust Project Developers); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Variables and Mutability; The Rust Project Developers, Variables and Mutability (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-variables-and-mutability"
tags: [rust, variables, mut, const, immutability]
client: Librarian
sources:
  - id: S1
    title: "Variables and Mutability"
    publisher: The Rust Project Developers
    url: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html
    accessed: 2026-11-27
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Variables and Mutability (source)"
    publisher: The Rust Project Developers
    url: https://raw.githubusercontent.com/rust-lang/book/main/src/ch03-01-variables-and-mutability.md
    accessed: 2026-11-27
    license: "MIT OR Apache-2.0"
---
# Rust variables: immutability by default, mut, and constants
**Answer:** By default, Rust variables are immutable, but you can opt into mutability with mut, and you can declare always-immutable constants with const.

## Immutable variables and mut

When a variable is immutable, once a value is bound to a name, you cannot change that value.

Assigning again to an immutable variable is a compile-time error, such as cannot assign twice to immutable variable x.

The compiler guarantees that a value you marked immutable will not change, which makes the code easier to reason through.

Mutability can still be useful.

You make a variable mutable by adding mut in front of the variable name, which also signals to later readers that other code will change the value.

## Constants

Like immutable variables, constants bind a value to a name and are not allowed to change, but they differ in several ways.

You cannot use mut with constants; they are always immutable, not merely immutable by default.

You declare them with the const keyword instead of let, and you must annotate the type.

Constants can be declared in any scope, including the global scope.

They may be set only to a constant expression, not a value that could only be computed at runtime.

The naming convention is all uppercase with underscores between words, as in THREE_HOURS_IN_SECONDS.

Constants remain valid for the entire time a program runs, within the scope where they were declared.

## See also

- [rust-ownership-borrowing](https://iinventedlight.com/library/notes/rust-ownership-borrowing/)
- [rust-structs](https://iinventedlight.com/library/notes/rust-structs/)
- [rust-slices](https://iinventedlight.com/library/notes/rust-slices/)

## Claims

- id: C1
  claim: Rust variables are immutable unless you opt out.
  source: S1
  evidence: "by default, variables are immutable"

- id: C2
  claim: Add mut in front of a variable name to make it mutable.
  source: S2
  evidence: "you can make them mutable by adding `mut`"

- id: C3
  claim: Constants are always immutable; you cannot use mut with them.
  source: S2
  evidence: "you aren't allowed to use `mut` with constants"

## Sources

- [S1] Variables and Mutability. The Rust Project Developers. https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html . License: MIT OR Apache-2.0. Accessed 2026-11-27.

- [S2] Variables and Mutability (source). The Rust Project Developers. https://raw.githubusercontent.com/rust-lang/book/main/src/ch03-01-variables-and-mutability.md . License: MIT OR Apache-2.0. Accessed 2026-11-27.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Project Developers, Variables and Mutability; The Rust Project Developers, Variables and Mutability (source). MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
